Methods and architectures for resource management

ABSTRACT

Resource management architectures implemented in computer systems to manage resources are described. In one embodiment, a general architecture includes a resource manager and multiple resource providers that support one or more resource consumers such as a system component or application. Each provider is associated with a resource and acts as the manager for the resource when interfacing with the resource manager. The resource manager arbitrates access to the resources provided by the resource providers on behalf of the consumers. A policy manager sets various policies that are used by the resource manager to allocate resources. A resource consumer creates an “activity” at the resource manager and builds one or more “configurations” that describe various sets of preferred resources required to perform the activity. Each resource consumer can specify one or more configurations for each activity.

RELATED APPLICATION

This is a divisional of and claims priority to U.S. patent applicationSer. No. 09/563,724, filed on May 2, 2000, the disclosure of which isincorporated by reference herein.

TECHNICAL FIELD

This invention relates to computers and more particularly, to systemsand methods for managing resources of the computers.

BACKGROUND

Computers are evolving well beyond their traditional desktop roots. Inaddition to conventional desktop applications (e.g., word processing,spreadsheets, email, etc.), today's personal computers (PCs) are askedto play audio and video files, play music CDs (compact discs), receiveand display broadcast is programming, and so forth. Much of thisevolution is being driven by the continued convergence of computing,Internet, telephony, and entertainment technologies.

As a result, the look, feel, and functionality of computers arecontinuing to evolve for different consumer and operating environments.For instance, computers designed for home entertainment might beimplemented as a set-top box or a game console, equipped with browsersoftware, one or more tuners, EPG (electronic programming guide)software, different audio/video drivers, and gaming software. Computersdesigned for office use may resemble conventional desktop PCs inappearance, but be implemented with broadcast tuners, DVD (digital videodisks) drives, stereo speakers with surround sound, and so forth, tooffer a more enhanced computing experience. The variety andfunctionality of portable computers are even wider ranging as thedemands of the mobile user increase.

As computers are asked to perform more diverse tasks, it is not uncommonfor users to expect performance of multiple tasks simultaneously. Due tothis increasing user demand, there is more demand being placed on theexisting resources to handle the various tasks. This unfortunately leadsto a greater likelihood that the computer may not have sufficientresources at a requested time to accomplish all of the taskssimultaneously.

This resource shortfall is perhaps most evident for computers designedfor the home entertainment environment. Such computers must not only beable to perform multiple functions simultaneously, but must also satisfythe demands of multiple different users. For instance, one user mayrequest that the entertainment computer record a program at a specifictime while another user may request the computer to tune to a differentprogram at the same time. This a problem if the computer only has onetuner because it cannot possibly accomplish both tasks concurrently.

In such situations, the computer is at a loss to distinguish which taskshould be performed and which should not. Today, applications obtainresources on first-come or last-come basis. Accordingly, theapplications control resource allocation irrespective of the users'desires. In the above example, if the television application seizescontrol of the tuner over the recorder application, the televisionapplication will control the resource (i.e., tuner) even though theusers may be far more interested in recording the first program ratherthan watching the second program. Once the application obtains theresource, the resource is held by the application until it explicitlyrelinquishes the resource.

Thus, as the demand for resources continues to grow, there is greaterneed for techniques to manage the resources and their allocation todifferent users and/or applications.

SUMMARY

Resource management architectures implemented in computer systems tomanage resources are described.

In the described implementation, a general architecture includes aresource manager and multiple resource providers that support one ormore resource consumers such as a system component or application. Eachprovider is associated with a resource and acts as the manager for theresource when interfacing with the resource manager. The resourcemanager arbitrates access to the resources provided by the resourceproviders on behalf of the consumers.

A policy manager may be optionally included in the architecture to setvarious policies that are used by the resource manager to allocateresources. One policy that can be used by the resource manager is apriority-based policy to determine which applications and/or users havepriority over others to use the resources.

In the described embodiment, each resource provider registers with theresource manager. A resource consumer creates an “activity” at theresource manager and builds one or more “configurations” that describevarious sets of resources required to perform the activity. The activityis implemented as a container data structure that holds theconfigurations, and each configuration is implemented as a datastructure that contains the identities of the resources. The resourcemanager maintains the activities and configurations.

In the described embodiment, each resource consumer can specify one ormore configurations for each activity. If multiple configurations arespecified, the resource consumer can rank them according to preference.This allows the resource consumers to be dynamically changed from oneconfiguration to another as operating conditions change. In one aspect,resources that are needed elsewhere by a higher priority resourceconsumer can be secured by asking a current resource consumer to use aless preferred configuration, or give up entirely its resourceconfiguration or particular needed resource. When those resourcessubsequently become available again, the resource manager can notify theresource consumer so that the resource consumer can request to upgradeto the preferred configuration.

In one embodiment, the resource manager exposes a set of applicationprogram interfaces (APIs). The resource consumers and resource providersuse the APIs to communicate with the resource manager and to performsuch functions as registering resources, creating activities, andbuilding configurations.

In one embodiment, the resource consumer is aware of only a subset ofthe resources (and hence their resource providers) that are necessaryfor the resource consumer to perform a task. These resources, in turn,may rely on other resources that are unknown to the resource consumer toperform the task. The resource providers are configured to receive callsto build the configurations. Those resource providers that are known tothe resource consumer are called directly by the resource consumer.Those resource providers that are not known to the resource consumer arecalled by the resource providers that use their resources.

In one embodiment, when the resource providers are called, they provideinformation to the resource manager that enables the resource manager tomanage one or more configurations. One particular implementation is ahierarchical tree configuration that describes resource dependenciesbetween the different resource providers. The hierarchical nature of theconfiguration facilitates resource reservation and error reporting tothe resource consumer.

In one embodiment, error notifications are generated when a resourcereservation fails or preemption occurs. The hierarchical nature of theconfiguration makes error reporting more efficient by tracing eachdependent resource provider through its parent(s) until a resourceprovider is found that is known to the resource consumer. This knownresource provider is then able to articulate the error to the resourceconsumer in terms that the resource consumer will understand. The reportcan take different forms. For example, the report may be a simplenotification that the requested known resource is unavailable. Thereport might also present different options to the resource consumer(e.g., alternate resource settings to use to perform the task).

One aspect of the described embodiment provides a trouble-shootingfeature that attempts to remedy errors at the resource provider levelrather than reporting the error to the resource consumer.

In one embodiment, an intelligent interface component is provided tointerface with the resource manager on behalf of the resource consumerso that the resource consumer does not need to know what resources itrequires. The interface component is designed to understand whichresources are needed for certain activities. The intelligent interfacecomponent acts as a proxy resource consumer that can receive calls fromthe resource consumer to build a particular configuration. Theintelligent interface component then interacts with the resource managerfor purposes of building the configurations and requesting reservationsof the resources.

In one embodiment, a so-called “stateless” provider is employed. Thestateless provider is designed so that the provider does not maintainresource allocation or ownership information, even for the resources itmanages. Specifically, and in the described embodiment, a statelessprovider has no concept of time or whether it is being requested now orin the future, but only what resources and how much of them are beingused at any given request. A separate scheduling component runs “whatif” scenarios to determine whether resources will be available atselected times in the future.

BRIEF DESCRIPTION OF THE DRAWINGS

The same numbers are used throughout the drawings to reference likeelements and features.

FIG. 1 is a block diagram of an exemplary computing unit in the form ofan entertainment computing unit in accordance with one embodiment.

FIG. 2 is a block diagram of an exemplary resource managementarchitecture that is implemented by the computing unit of FIG. 1.

FIG. 3 is a flow diagram that describes steps in an exemplary resourcemanagement method that is implemented by the FIG. 2 resource managementarchitecture.

FIG. 4 is a block diagram that illustrates an exemplary resourcereservation process in accordance with the described embodiment.

FIG. 5 is a block diagram that illustrates different exemplarystructures that are utilized in a resource reservation process inaccordance with the described embodiment.

FIG. 6 is a flow diagram that describes steps in a resource allocationmethod using priority-based preemption in accordance with the describedembodiment.

FIGS. 7-10 are block diagrams that illustrate different scenarios forresource allocation using priority-based preemption in accordance withthe described embodiment.

FIG. 11 is a flow diagram that describes steps in a method fordynamically downgrading from a more preferred configuration to a lesspreferred configuration in accordance with the described embodiment.

FIG. 12 is a block diagram that illustrates one scenario in a method ofdowngrading to a less preferred configuration in accordance with thedescribed embodiment.

FIG. 13 is a flow diagram that describes steps in a method fordynamically upgrading from a less preferred configuration to a morepreferred configuration in accordance with the described embodiment.

FIG. 14 is a block diagram that illustrates one scenario in a method ofupgrading to a more preferred configuration in accordance with thedescribed embodiment.

FIG. 15 is a block diagram that illustrates one scenario in a method ofbuilding a configuration.

FIG. 16 is a flow diagram that describes steps in a configurationbuilding method in accordance with the described embodiment.

FIG. 17 is a flow diagram that describes steps in an error reportingmethod in accordance with the described embodiment.

FIG. 18 is a block diagram of an exemplary policy managementarchitecture, further illustrating a policy manager implemented with theresource management architecture of FIG. 2.

FIG. 19 is a flow diagram that describes steps in an exemplary policymanagement method that is implemented by the FIG. 18 policy managementarchitecture.

FIG. 20 is a block diagram of another exemplary resource managementarchitecture that is similar to that of FIG. 2, but further includes anintelligent interface component.

FIG. 21 is a block diagram of yet another exemplary resource managementarchitecture that is similar to that of FIG. 2, but further includes ascheduling component.

DETAILED DESCRIPTION

This disclosure describes a resource management architecture formanaging resources in a computer system. A resource is a finite quantityof a computing component in the computer system that is utilized toperform various tasks or functions. Examples of resources includehardware devices, ports, CPU processing, memory, USB bandwidth, networkbandwidth, software modules, and so forth. A resource may be a physicalhardware quantity (e.g., CPU, USB bandwidth, network bandwidth) or anabstract quantity (e.g., virtual memory, audio volume).

Managing limited resources is becoming increasingly important ascomputer systems are asked to perform more tasks simultaneously, and formultiple users. Consider, for example, a TV-enabled computing system(e.g., broadcast PC, set-top box, etc.) that has a single TV tuner.There may be multiple processes that need to use the TV tuner in orderto do their processing. For instance, a TV viewer application needs theTV tuner to provide a video stream that the application displays on amonitor. A TV recorder application might also need the TV tuner toprovide a video stream that the application encodes and records on ahard disk for later playback. Unfortunately, the TV tuner can only tuneto one TV channel at a time. If there is only one TV tuner in thesystem, the system is forced to choose between watching a show orrecording a show as it cannot do both at the same time (unless bothapplications want to tune to the same TV channel).

In another situation, perhaps multiple applications concurrently requirebandwidth on a Universal Serial Bus (USB). One application might specifybandwidth requirements that consume 20% of the existing USB bandwidth,while another might specify bandwidth that would consume 15%. Furthersuppose that a combined bandwidth, if all requests were met, wouldexceed the available USB bandwidth. In this scenario, one or more of theapplications might be prevented from gaining access to the USB resourceand/or be allocated less than the requested amount.

Among other features, various embodiments of the resource managementarchitecture described herein have the following characteristics:

-   -   Allocates resources based on relative priorities (ultimately as        set by the end-user defined policies).    -   Dynamically allocates and deal locates resources.    -   Allows resources to be reclaimed from a lower priority resource        consumer in favor of reassigning them to a higher priority        consumer.    -   Provides automatic notifications to consumers when additional        resources become available.    -   Allows resources to be added (registered) and removed        (unregistered) dynamically.    -   Provides a mechanism for detailed reporting of resource        conflicts.    -   Allows multiple resources to be acquired automatically.    -   Allows dynamic changes to the priority of activities.    -   Allows dynamic changes to the ranking of resource        configurations.    -   Provides a framework such that any third party can register a        resource to be exposed.    -   Provides a resource-agnostic framework in which any consumer and        resource pair can negotiate properties unique to them.    -   Allows resource allocation to be done in advance of the actual        need for resource usage (resource scheduling).    -   Provides mechanisms to prevent consumers from using resources        without first reserving them.    -   Allows a consumer to specify a range of configurations, ranking        them from most desirable to least desirable.    -   Provides mechanisms to automatically release resources when the        process abnormally terminates while holding resources, thereby        preventing resource leaks.    -   Allows for legacy applications to co-exist with the resource        management architecture.

The resource management architecture may be implemented in many diverseenvironments and computing contexts. For discussion purposes, thearchitecture is described in the context of a computing system for theconsumer entertainment environment, which might take the form of abroadcast-enabled personal computer, a set-top box (STB), or a gameconsole. After describing one suitable system for implementing theresource manager architecture, the architecture is explored in greaterdetail with reference to FIG. 2 under the heading “General ResourceManagement Architecture”.

Exemplary System

FIG. 1 shows an entertainment computing system 20 having a computingunit 22 and multiple peripheral components that connect or otherwiseinterface with the computing unit 22. The computing unit 22 has one ormore processors 24(1), 24(2), . . . , 24(P), volatile memory 26 (e.g.,RAM), and non-volatile memory 28 (e.g., ROM, Flash, hard disk, CD ROM,etc.).

An operating system 30 is stored in non-volatile memory 28. Theoperating system 30 is a multi-tasking operating system that, whenloaded into volatile memory 26 and executed on one or more processors24, supports simultaneous execution of multiple applications 32(1),32(2), . . . , 32(A). One preferred operating system is a Windows-brandoperating system sold by Microsoft Corporation. It is noted, however,that other operating systems may be employed.

Applications 32(1)-32(A) are representative of many diverse types ofapplication programs that may be run on the entertainment computingsystem 20. Examples include an EPG (Electronic Programming Guide)program, browser, channel navigation, audio and video players,audio/video recording program, stereo program, games, audio/videoteleconferencing, and so forth. A software decoder 34 (e.g., an MPEGsoftware decoder) and other software resources 36 are also shown storedin non-volatile memory 28.

The operating system 30 has a resource management system 40 that managesthe resources of the entertainment computing system 20 for allocation tothe applications 32(1)-32(A). The resource management system 40 may beimplemented separately from the operating system 30, but is illustratedas being integrated within the operating system. The resource managementsystem 40 is described below in more detail with reference to FIG. 2.

The operating system 30 also has multiple software drivers 42(1), . . ., 42(D) for various associated peripheral components in the computingsystem 20. One or more COM (communication) ports 44 are also illustratedas being part of the operating system 30. A representative collection ofperipheral components is illustrated surrounding the computing unit 22.The entertainment computing system 20 has one or more receivers 50 toreceive broadcast data, such as television programming and the like. Thereceiver(s) 50 may be an analog television receiver, a digital broadcastreceiver (e.g., satellite dish, cable modem), an RF receiver, and soforth. The receiver(s) 50 are coupled to one or more tuners 52(1)-52(T)which tune to frequencies of the carrier signals transporting the data.

A USB bus 54 is connected to the computing unit 22 to interface manydifferent kinds of USB compatible peripheral components. Examples ofsuch components include a modem 56, speakers 58, a still or video camera60, and other USB devices 62.

One or more hardware decoders 64(1), 64(2), . . . , 64(H) are coupled tothe computing unit 22 to decode various types of data streams. Exemplarydecoders include video decoders, which use such standards as MPEG-1,MPEG-2, MPEG-4, H.261, and H.263, and audio decoders The computing unit22 is coupled to a network 66 to interface with other computers. Thenetwork 66 is representative of many diverse types of networks,including LANs, WANs, Internet, intranets, and wireless networks. One ofthe resources managed by the resource management system 40 is thebandwidth afforded at any given time by the network 66.

A 1394 serial bus 68 is connected to the computing unit 22 to interfacemany different kinds of 1394 compatible peripheral components. Examplesof such components include memory drives 70 (e.g., disk drive, tapedrive, CD ROM drive, etc.), modem 72, speakers 74, a CPU (centralprocessing unit) 76, and other 1394 devices 78. It is noted thatalthough USIB and 1394 buses are shown in this exemplary system, otherbus architectures may be additionally or alternatively used, such asSCSI, ISA (Industry Standard Architecture), and PCI (PeripheralComponent Interconnect) buses.

The entertainment computing system 20 has a display 80, which may be atelevision set or a computer monitor. The display is interfaced with thecomputing unit 22 via one or more display interfaces 82(1), 82(2), . . ., 82(C), which are representative of a video port, overlay, and videomemory.

Other exemplary peripheral devices coupled to the computing unit 22include DVD) player 84, an EPG database 86, and a video recorder 88. TheEPG database 86 holds the programming information that fills the tilesof the EPG user interface (UI). The programming information includessuch items as program title, start time, duration, actor/actress,summary description, and so forth. The EPG information is received vianormal means (e.g., via cable modem or embedded within the verticalblanking interval) and stored in the EPG database 86. The computing unit22 runs queries on the EPG database to locate shows or other programmingcontent, and presents the information to the user in a graphical UI.

The video recorder 88 may be in the form of a video cassette recorder, adisk-based recorder, and the like. The computing unit 22 can direct thevideo recorder 88 to record various programming received via the tuners52 or over the network 66.

In addition to the entertainment-focused components described above, itis further noted that the computing system 20 may also be configured asa fully functional computer that can perform typical desktopapplications familiar to computers. A variety of different applicationscan be loaded and executed on the system, such as word processingapplications, spreadsheet applications, database applications,scheduling applications, financial applications, educationalapplications, and so forth.

The collection of components illustrated in FIG. 1 shows exemplary typesof resources that are managed by the resource management system 40.Among them are ports, tuners, decoders, USB bandwidth and devices on theUSB bus, network bandwidth, 1394 devices, display interfaces, recorders,memory drives, and so on. Many other components may be added to thesystem, and one or more of the illustrated components can be removed.

General Resource Management Architecture

FIG. 2 shows one exemplary resource management architecture 100 that isimplemented by the entertainment computing system 20 of FIG. 1. Thearchitecture 100 is implemented in software, and in this example,includes components at the user level as well as components at thekernel level.

The architecture 100 has a resource manager 102 and multiple providers104(1), 104(2), 104(3), . . . , 104(P), which support one or moreresource consumers. Examples of resource consumers include user-levelresource consumers, such as applications 32(1), 32(2), . . . 32(A) andkernel-level resource consumers, such as resource consumer 35. Eachprovider 104(1)-104(P) is associated with a resource and tracks theavailability of the resource. As noted above, a resource is a finitequantity of a computing component in the computer system that isutilized to perform various tasks or functions. Accordingly, examples ofresource providers include drivers that own hardware devices (e.g., suchas a driver for TV tuner, a USB driver that owns bandwidth on the bus, aCPU scheduler for CPU time resource), hardware components (e.g.,decoders), and software modules (e.g., software decoders). It is furthernoted that a single driver may provide multiple resources, in which casethe resource manager 102 sees the driver as multiple providers. Althoughthe resource providers are illustrated at the kernel level, one or moreresource providers may also be implemented at the user level.

Each provider 104 has a resource quantifier 106 that determines theamount of resource available for allocation by the resource manager 102.The resource quantifier 106 is configured to calculate the availabilityin different ways depending upon how the quantity of any given resourceis measured. One way is to keep a finite count. For instance, a resourcequantifier 106 for a provider of tuning resources may be implemented asa counter that identifies how many tuners are free to be used.

Another way to calculate resource availability is as a percentage. Aresource quantifier 106 for a provider of network resources may beimplemented to compute the percentage of bandwidth currently availablefor use. A time-based metric may also be used to calculate resourceavailability. An example of this metric is a resource quantifier for aCPU that identifies how much processing time the CPU can currentlyoffer. Other ways of calculating the availability of given resourcescan, of course, be used.

Each resource provider 104 registers itself with the resource manager102 and supplies a set of callbacks used by the resource manager 102 toget information. For example, one callback is used to perform theresource calculations and another is used to notify the provider ofsuccessful reservations.

The resource manager 102 arbitrates access to the resources (local orremote) provided by the resource providers 104. Resource consumers, suchas applications 32, request sets of one or more resources provided bythe providers 104, and the resource manager 102 determines whichapplications get to use which resources of the providers. The resourcemanager 102 makes resource allocation decisions based on a predeterminedconflict resolution mechanism. In one implementation, the conflictresolution mechanism is priority based, and hence the resource manager102 arbitrates access to resources based priority. In anotherimplementation, the conflict resolution mechanism may be based on loadbalancing which attempts to maximize the number of activities that canproceed at any given time.

A separate and independent policy manager 108 may optionally beimplemented to set policies with respect to the conflict resolutionmechanism being used by the resource manager. For instance, if theresource manager is employing a priority based resolution, the policymanager 108 ranks tasks a priori according to their relative importanceascribed by the user or system so that the resource manager maydetermine which task should get access to resources when there is aconflict such that not all tasks can be allocated their resources. Otherviable policies include first reservations win, most recent reservationswin, “fair” sharing of resources, user picks what wins over what, and soforth. Many different policies are possible.

The system or user sets the policies 110 and the policy manager 108translates them into absolute priorities. The resource manager 108 maybe implemented with components at both the user level and the kernellevel.

Generally speaking, a resource consumer is any entity that requiresresources to perform a task. As noted above, applications 32 are oneexample of a resource consumer. As another example, resource providersmay themselves be consumers of other resources. For purposes ofdiscussion, applications are assumed to be the primary consumers andhence the description references applications 32 as requesting andconsuming resources. This should not be taken as a limitation to thearchitecture, however, as other types of consumers may be utilized.

The resource manager 102 exposes a defined API (application programinterface) 120 to interact with other modules in the architecture. TheAPI 120 includes a set of provider API calls used by the providers 104and a set of consumer API calls to accept requests for resources fromthe applications 32(1)-32(A) or other resource consumers. One API isdescribed below in detail under the heading “Resource Manager API”.

When an application 32 wants to perform a task, it uses the API 120 tocreate an activity 122 at the resource manager 102 and build one or moreconfigurations 124 describing various sets of resources required toperform the activity. An activity is a data structure associated with atask being performed in the system. One activity exists per task beingperformed. In FIG. 2, activities 122(1), . . . , 122(N) are illustratedat resource manager 102. The resource manager 102 decides whichactivities can be satisfied in their entirety from the limited pool ofresources and allows the applications with activities that can besatisfied to have access to the requested resources.

A configuration is a data structure holding a collection of one or moreresource descriptors 126 for corresponding resources needed to perform atask in the system. The activity data structure is a container thatholds one or more configurations. In FIG. 2, two configurations 124(1)and 124(2) are shown within the first activity 122(1). The firstconfiguration 124(1) contains four descriptors R₁, R₂, R₃, and R₄ toidentify corresponding resource providers that control the resourcesrequired to perform the task and to specify the amounts of thoseresources that are needed. The second configuration 124(2) containsthree descriptors R₂, R₄, and R₅ to identify corresponding resourceproviders that control the resources required to perform the task and tospecify the amounts of those resources that are needed. The activity122(1) can successfully complete its task with any one of theconfigurations 124.

Each resource descriptor 126 represents an instance of a resourcerequired by a resource consumer to perform a task. It contains thefollowing information: (1) an identity field 128 to hold the identity ofthe resource provider 104 that owns the resource; (2) an optional amountfield 130 to hold the quantity of resource needed for thatconfiguration; and (3) an attribute field 132 to list one or moreresource attributes. The amount held in field 130 is opaque to theresource manager, and is a value that only needs to be understood by theprovider and consumer. Similarly, an attribute is other data that onlythe provider and consumer understand, but is opaque to the resourcemanager. In the context of tuners, for example, a resource attributemight be the tuner frequency that a resource consumer wants.

Each application might specify one or more configurations for eachactivity, as illustrated by two configurations 124(1) and 124(2) foractivity 122(1). Configurations may be added to an activity at any time,regardless of whether the activity has resources reserved. If multipleconfigurations are specified, the application ranks them according to apreference or desirability level and the resource manager 102 attemptsto satisfy the most desirable configuration. Here, the firstconfiguration 124(1) is identified as being more preferred or having ahigher desirability, as indicated by the “H”. The second configuration124(2) is identified as being less preferred or having a lowerdesirability, as indicated by the “L”.

With multiple configurations, the resource manager 102 is able toflexibly and dynamically change from one configuration for anapplication to another as the operating conditions change. For instance,if resources are needed elsewhere by a higher priority application, thecurrent application may be asked to use a less preferred or “fallback”configuration that enables the needed resources to be reallocated to thehigher priority application. When those resources subsequently becomeavailable again, the resource manager 102 can notify the application sothat the application can request to upgrade to the preferredconfiguration. Dynamically changing to a fallback configuration andupgrading to a more preferential configuration are described in moredetail below under the headings “Fallback Configuration” and “UpgradeNotification”.

The resource descriptors 126 may be organized as a tree to represent anyinherent reliance among the resources. That is, a resource provider inturn consumes resources from other providers. For example, a USB cameradriver is a provider of the camera resource and a consumer of bandwidthprovided by the USB bus driver. Such relationships are represented as atree of resource descriptors.

In the tree metaphor, the configuration 124 can be thought of as theroot of the descriptor tree. In FIG. 2, there are four resourcedescriptors 126 in the first configuration 124(1) that are organized ina tree. The tree contains two side-by-side sibling nodes R₂ and R₄ torepresent that the resources provided by the corresponding resourceproviders are both required to perform the requested task. A child nodeR₃ branches from descriptor R₄ to indicate that the provider referencedby R₄ is a consumer of the resource referenced by descriptor R₃.Similarly, node R₁ branches from descriptor R₃ to indicate that theprovider referenced by R₃ is a consumer of the resource referenced bydescriptor R₁.

General Operation

FIG. 3 shows the general operation of the resource managementarchitecture 100 in accordance with the described embodiment. Theprocess is performed in software and will be described with additionalreference to FIG. 2.

At step 300, each of the resource providers 104(1)-104(P) register theresources it manages with the resource manager 102. Registration (andunregistration) can occur at any time. Each resource provider 104 uses afunction call “RmRegisterResource” in the resource manager API 120 toregister its resource with the resource manager 102. Each resource hasan associated type specific GUID (Globally Unique IDentifier) toidentify the type of resource, and this GUID is passed in as part of thefunction call. A single provider 104 can register multiple types.Similarly, multiple providers can register for the same resource type.

As part of the registration process, the resource provider 104 specifiesa set of callbacks that the resource manager 102 will use to reserve andrelease resources on behalf of a consumer. The RmRegisterResourceprocess returns a handle to be used in other calls into the resourcemanager.

According to the architecture 100, consumers go through the resourcemanager 102 only to reserve and release resources. Otherwise, theconsumers directly access the resource provider 104 to add appropriateresource descriptors to a configuration and to use the resources oncethey are reserved, as described below in more detail.

At step 302, a resource consumer creates one or more activities toperform one or more associated tasks. As an example, suppose application32(1) creates an activity 122(1) in resource manager 102. Theapplication 32(1) uses a function call “RmCreateActivity” to registerthe activity with the resource manager 102. This process creates thecontainer data structure forming the activity 122(1) and produces anactivity handle for the activity 122(1).

At step 304, the resource consumer builds one or more configurationswithin each activity. If more than one configuration is specified, theresource consumer ranks each configuration in the activity in terms ofdesirability within the scope of that activity. In the FIG. 2 example,application 32(1) builds at least two configurations 124(1) and 124(2)within the first activity 122(1) using the function call“RmCreateConfiguration”. This process produces a handle to theconfiguration structures 124(1) and 124(2).

Once the configurations 124 are created, the resource consumer startsadding, via associated providers, the resource descriptors to theconfigurations (step 306 in FIG. 3). In the FIG. 2 example, application32(1) begins adding descriptors, such as R₂ and R₄, to the firstconfiguration 124(1) using corresponding resource providers 104. Theproviders 104 utilize a function call “RmAddResourceToConfiguration”from the resource manager API to add the descriptors to theconfigurations. As descriptors 126 are added, their correspondingresource providers 104 may call other providers (usually lower in thestack) to add dependent resource descriptors. Here, the resourceprovider identified by descriptor R₄ calls the resource provideridentified by descriptor R₃, which in turn calls the resource provideridentified by descriptor R₁.

At step 308, the consumer contacts the resource manager to reserveresources for an activity. The resource manager, in turn, contacts theresource providers and reserves resources, if available, on behalf ofthe consumers. The resource manager attempts to reserve every resourceidentified in the descriptor configuration tree. If resources are notavailable, the resource manager arbitrates among the activities andresolves conflicts as to which consumer(s) are granted access to theresources. The consumer can utilize the allocated amount of resourceuntil either the consumer voluntarily relinquishes the resources oruntil the resources are pre-empted by the Resource Manager.

One implementation of the reservation and arbitration step 308 isillustrated as substeps 320-330. At step 320, a consumer specifies whichconfiguration 124 in the activity 122 to reserve. If no configuration isspecified, the resource manager 102 attempts to reserve theconfigurations in order of desirability. In our continuing example, theapplication 32(1) uses a function call “RmReserveResources” to directthe resource manager 102 to reserve the resource specified in thepreferred configuration 124(1). This configuration 124(1) requiresresources from providers identified by descriptors R₁, R₂, R₃, and R₄.

At step 322, for each resource descriptor 126 in the configuration, theresource manager 102 identifies the corresponding resource provider 104and makes a list of all activities 122 in the system that currently areusing resources from this resource provider. The activity 122(1) to bereserved is also added to this list. The resource manager 102 assignsresources to all descriptors contained in the listed activities (step324) using a provider supplied “resource allocation” function. In apriority-based scheme, the activities in the list have associatedpriorities and the resource manager 102 starts with the highest priorityactivity when assigning resources. The resource manager 102 iteratesthrough the list of activities until it reaches the end or the providerruns out of resources. A more detailed description of an exemplaryresource calculation is given below in the next section, under theheading “Exemplary Resource Reservation Calculation”.

A configuration is said to be reserved when all the resource descriptorsin it are reserved. A resource descriptor is said to be reserved whenresources are assigned to it. Steps 322 and 324 are repeated for everyresource/resource provider in the configuration (step 326).

At step 328, the resource manager 102 determines whether eachreservation is successful in that all requested resources are available.If the reservation succeeds, the resource manager 102 notifies theresource providers 104 of the reservation so that they can validateconsumer requests to use the resources (step 330). In this manner, theproviders 104 can catch rogue consumers as well as legitimate consumersthat attempt to use resources without first reserving them. Forinstance, a legitimate program might attempt to use a CPU resourcewithout first reserving it. Likewise, a USB mouse will use USB bandwidthwithout first having reserved it. In such situations, the providersassociated with the CPU and USP bandwidth will be able to discern thatthe program or USB mouse has not yet reserved the resources.

If the reservation fails (meaning that all requested resources are notavailable), the resource manager 102 notifies the resource providers 104of the reservation failure (step 332). The resource manager 102 thenperforms one or both of the following tasks: (1) try a less preferredconfiguration, if one is available and the consumer did not specify aconfiguration to reserve (step 334), and/or (2) report an error to therequesting consumer.

Exemplary Resource Reservation Calculation

FIG. 4 illustrates an exemplary resource reservation process employed aspart of the reservation and arbitration step 308 (more particularly,steps 322-326) in FIG. 3. In step 308 of FIG. 37 the resource manager102 reserves resources on behalf of the consumers, such as applications32. FIG. 4 shows three activities A1, A2, and A3, which are generallyreferenced by numbers 400(1), 400(2), and 400(3). The activities areconstructed and reside at the resource manager 102. Each of theactivities has an associated priority, whereby the first activity A1 hasthe highest priority, the second activity A2 has the medium priority,and the third activity A3 has the lowest priority (i.e., A1>A2>A3).

The “priority” of an activity indicates a user or system preference. Itis not used in the sense of a traditional thread or process priority.Specifically, an activity priority defines an arbitration policy betweenconsumers contending for the same resources. In the describedimplementation, the policy manager 108 assigns priorities to each of theactivities. Notice that the priorities are assigned to an activity asopposed to individual resources. In this manner, the resource managercan reclaim resources from lower priority activities to satisfy thereservation request of a higher priority activity.

In this example, each activity 400(1)-400(3) has only one configuration402(1)-402(3). Descriptors R₁ and R₂ represent corresponding resourceproviders that have registered with the resource manager. Activities A1and A2 have both descriptors R₁ and R₂, whereas activity A3 has onlydescriptor R₁. For this example, assume that the highest and lowestpriority activities A1 and A3 are reserved and the resource manager getsa request to reserve the medium priority activity A2. The resourcemanager performs the following five steps to reserve A2.

Step 1: The resource manager goes through its internal states and makesan activity list of all activities that are reserved (i.e., step 322 ofFIG. 3). At this point, the list contains the reserved activities A1 andA3. The resource manager then adds the activity A2 to the list and sortsthe resulting list in descending order of priority. This results in anactivity list containing, in order, the highest priority activity A1,followed by the medium priority activity A2, followed by the lowestpriority activity A3.

FIG. 5 shows an activity list 500 showing the three activities in orderof priority. The activity list 500 is maintained at the resourcemanager.

Step 2: For each resource descriptor in activity A2, the resourcemanager determines if there are sufficient resources to satisfy therequest, thereby allowing the resource manager to reserve the resourcedescriptor for the activity. This is done by first making a list ofresource descriptors in all activities in the activity list 500 that usethe same provider as referenced by the resource descriptor that is to bereserved. For example, to reserve A2-R₁ (i.e., the descriptor R₁ inApplication A2), the resource manager constructs a separate resourcedescriptor list of all resource descriptors R₁ in activities listed inthe activity list 500. The list is also in descending order of priority.

FIG. 5 shows two descriptor lists 502(1) and 502(2). The first list502(1) contains all resource descriptors R₁ in the activities A1-A3listed in the activity list 500, in descending order of priority:A1-R₁−1, A1-R₁−2 (i.e., a second use of provider R₁ in activity A1),A2-R₁, and A3-R₁. The second list 502(2) contains all resourcedescriptors R₂ in the activities A1-A3 listed in the activity list 500,in descending order of priority: A1-R₂, A2-R₂−1, and A2-R₂−2. Thedescriptor lists 502 are maintained at the resource manager.

Step 3: After the descriptor lists 502 are completed, the resourcemanager creates a buffer 504 that holds an accumulated value 506representing the increasing amount of resources allocated to variousactivities. For each element in the R₁ descriptor list 502(1), theresource manager calls the resource provider R₁'s “add accumulator”function and passes in the resource descriptor (i.e., A1-R₁−1, A1-R₁−2,etc.), the accumulator buffer 504 and the resource provider's resourcequantifier 106 (FIG. 2). The resource manager makes similar calls foreach element in the R₂ descriptor list 502(2).

The add accumulator function determines the resource amount required forthe resource descriptor and adds it to the contents of accumulatorbuffer 504. If the new value in buffer 504 exceeds the maximum amount ofresources in the resource provider R₁, the add accumulator functionreturns an error indicating that the provider cannot satisfy thisallocation due to shortage of resources. The resource manager tags theactivity associated with such resource descriptors as “victims.” Forexample, if the calculation on resource descriptor A3-R₁ fails, activityA3 is tagged as victim. If the activity being reserved, A2, is marked asa victim, the resource manager bails out to step 332 of FIG. 3, notingthat it is not possible to reserve the configuration in activity A2.

Step 4: After processing all resources descriptors in the resourcedescriptor lists constructed in Step 2, the resource manager evaluatesif there are any victim activities. If there are no victim activities,the resource manager was able to successfully reserve the activity A2.The providers of all resource descriptors in A2 are notified of the newreservation. This allows providers to validate a consumer's request toaccess a resource; conversely, it can catch rogue consumers that attemptto use resources without reserving.

Step 5: On the other hand, if there are victim activities at the end ofstep 3, the resource manager notifies those activities to release theresources. When the resources are released, the resource manager assignsthem to the activity that originally made the request (A2 in this case).For instance, suppose that activity A3 is tagged as a victim in step 3.The resource manager notifies the activity A3 to release its resourcesand reallocates them to the requesting activity A2. This makes sensebecause the activity A2 has a higher priority than activity A3 and thus,the limited resources should be shifted from the lower priority activityA3 to the higher priority activity A2.

Resource Allocation Using Priority-Based Preemption

The resource management architecture 100 shown in FIG. 2 may employdifferent types of strategies to allocate resources among the variousactivities being requested by resource consumers. For instance, onestrategy might be to optimize resources among as many activities aspossible. Another strategy is to allocate resources according to somepriority criteria. It is this latter strategy that is of interest inthis section.

A priority-based strategy allocates resources based upon whichapplications and/or users have priority over others to use theresources. Again, the term “priority” is not used in the sense of atraditional thread or process priority, but in the context of anarbitration policy between consumers contending for the same resources.Priorities are assigned to an activity as opposed to individualresources.

priority-based strategy permits activities to be ranked by importance,e.g., activities that are more “important” to the user could bedesignated to have higher priority. This allows the resource managementarchitecture to migrate desired, but limited, resources away from theless important activities to the more important activities. Determiningwhat constitutes “more important” and “less important” is the venue ofthe policy manager 108 and the policies 110, and this is described belowin more detail under the heading “Policy Manager”. For the presentdiscussion on preemption, however, it is assumed that there is somepriority rating that ranks activities in some manner, such as theirrelative importance to other activities. As an example, in the absenceof a policy manager 108, the activity priorities may be assigned in afirst come, first served basis.

With priority-based preemption, the resource manager effectively“preempts” the lower priority activity that is currently using theresources and dynamically shifts the resources to the higher priorityactivity. The resource manager notifies the lower priority activity thatits right to use the resources is suspended. This gives the lowerpriority activity an opportunity to stop using the resources in acontrolled, clean manner, or alternatively, a chance to react andpossibly complete its processing in an alternative manner.

The resource manager in cooperation with the application from which theresource is reclaimed accomplishes the preemption process. As shown inFIG. 2, the resource manager 102 maintains one or more activitystructures 122 that are assigned a priority within the system. Eachactivity has one or more configuration structures 124 that specify a setof resources the activity needs to accomplish its task. The resourcemanager 102 also tracks which activities have been granted resources fortheir configurations and maintains communication with each resourceprovider 104 maintains the communication needed with each resourceprovider 104 and the state needed for each resource provider to trackhow much of the resource they provide is currently available.

FIG. 6 shows the resource allocation process using priority-basedpreemption. The steps are performed in software by the resource managerand resource providers (as illustrated graphically), and are describedwith additional reference to FIG. 2.

At step 600, the resource manager 102 receives a request from a consumer(e.g., application) to create an activity 122 for performing a certaintask. One or more configurations 124 are designated as part of theactivity. The consumer then reserves a configuration. The resourcemanager 102 asks each registered resource provider 104 identified in theconfiguration 124 to determine whether it can allocate its resource tothe activity 122 (step 602).

If the providers 104 have sufficient resources to satisfy the newconfiguration, the resource manager allocates the resources to theactivity (i.e., the “yes” branch from step 604 and step 606). Otherwise,if any provider 104 does not have sufficient resources left to satisfythe configuration, it notifies the resource manager 102 of this lack ofresources (i.e., the “no” branch from step 604 and step 608).

The resource manager 102 checks all configurations 124 of all activities122 with a lower priority than the one currently requesting resources todetermine if any lower priority activity is currently using resourcesthat, if reallocated to the new higher priority activity, would satisfythe configuration of the higher priority activity (step 610). If no suchlower priority activity, or combination of lower priority activities,exists (i.e., the “no” branch from step 612), the resource manager 102notifies the higher-priority activity that its configuration ofresources cannot be currently satisfied (step 614).

On the other hand, if a lower priority activity exists from whichresources can be taken (i.e., the “yes” branch from step 612), theresource manager 102 determines whether all resources in the newhigher-priority activity, including those resources currently reservedin the lower priority activity, can be reserved (step 616). If not(i.e., the “no” branch from step 616, the resource manager 102 notifiesthe higher-priority activity that its configuration of resources cannotbe currently satisfied (step 614). Conversely, if the resources can bereserved, the resource manager 102 sends a preemption notificationinforming each of the lower priority activities that it must give up itsresources (step 618). The lower priority activities are then given anopportunity to reduce its resource reservations in a controlled mannerto free of resources for reallocation to higher priority activities, oralternatively, a chance to react and possibly complete its processing inan alternative manner (step 620). When all lower priority activitieshave released all resources they are currently using, the resourcemanager 102 notifies the new, higher priority activity that it canproceed to allocate the resources it needs (step 622). In this manner,the lower priority processes are preempted of their use of limitedresources that are needed by higher priority processes.

It is noted that in the event that a lower priority process does notwillingly give up its resources upon receiving the preemption noticefrom the resource manager, the resource manager is capable of revokingthe activity's reservations and/or terminating the process associatedwith the lower priority activity and forcibly reclaiming its resources.

FIGS. 7-10 show different scenarios to illustrate resource allocationusing priority-based preemption. Each figure shows one or moreactivities that exist at the resource manager 102 and the attempt to addone more activity. Each of the existing and new activities has anassociated priority. For ease of discussion, each activity is assumed tohave only one configuration.

FIG. 7 illustrates the case where two activities wish to utilize thesame resource, but unfortunately, the resource can only be allocated toone of the two activities. For example, suppose the resource is a tunerand the system only has one tuner. The two activities A1 and A2(referenced generally by numbers 700(1) and 700(2)) have correspondingconfigurations 702(1)-702(2), each with the identical descriptor torepresent the same corresponding resource provider.

In the FIG. 7 case, the existing activity A1 has the highest priorityand the new activity A2 seeking to be added has the lowest priority(i.e., A1>A2). According to the priority-based preemption process ofFIG. 6, the resource manager runs the “resource calculation” on A1 firstby contacting the resource provider identified by descriptor R₁. Asdescribed in the “resource calculation” method earlier, the provideradds the amount of resource required by this descriptor to theaccumulator. The new value of accumulator becomes 1. The providercompares the accumulator value to the total amount of resources it has(1 in this case) and indicates to the resource manager it can satisfythe amount. The resource manager repeats this same protocol for activityA2 with the “accumulator” initialized to 1. The provider adds the amountof resources required for activity A2 (step 602 in FIG. 6) to contentsof the accumulator and finds it exceeds the total amount of resourcesthat it has. The resource provider returns a notice that it cannotsatisfy the request given its current allocation (steps 604 and 608).The resource manager then evaluates whether there is any lower priorityactivity that is currently using the requested resource (step 610). Inthis case, the current user of the resource is the existing activity A1,which has a higher priority than that of the new activity A2.Accordingly, the resource manager informs the new activity that itsconfiguration cannot be satisfied at this time (steps 612 and 614).

FIG. 8 illustrates a similar case to that of FIG. 7, except that the newactivity has a higher priority than the existing activity. The twoactivities A1 and A2 (referenced generally by numbers 800(1) and 800(2))have corresponding configurations 802(1)-802(2), each with a descriptorto represent a corresponding resource provider. In this case, theexisting activity A1 has a lower priority than the new activity A2(i.e., A1<A2).

According to the priority-based preemption process of FIG. 6, theresource manager asks the resource provider identified by descriptor R₁to determine whether it can allocate resources to the new activity A2(step 602 in FIG. 6). The resource provider returns a notice that itcannot satisfy the request given its current allocation (steps 604 and608).

The resource manager then evaluates whether there is any lower priorityactivity that is currently using the requested resource (step 610). Inthis case, the current user of the resource is the existing activity A1,which has a lower priority than that of the new activity A2.Accordingly, the resource manager sends a preemption notice to the lowerpriority activity A1 (steps 616) and allows the lower priority activityto stop or complete (step 618). The resource manager informs the new,higher-priority, activity A2 that it will be allocated its requestedresources (step 620). Accordingly, FIG. 8 represents the case where theresource manager dynamically migrates resources from an existingactivity to a new activity, thereby victimizing the existing activityfor the sake of a higher priority new activity.

FIG. 9 illustrates a case where the victim activity is asked to releaseor reduce its usage of a resource. In this case, the victim activity iscurrently reserving other resources R₁, R₂, and R₄, which have not beenrequested by the resource manager. In such a case, the consumer thatowns the activity can decide whether to release all of the resources,release all of the resource required by the resource manager, or releasea portion of the resource required by the resource manager. Fordiscussion purposes, suppose the resource R₃ pertains to the CPUresource, and the consumer associated with activity A1 desires to reduceits usage of the CPU to 40% usage in response to a request from activityA2 for 50% of the CPU.

In FIG. 9, an existing low-priority activity A1 (referenced generally asis number 900(1)) has a corresponding configuration 902(1), with fourresources represented by descriptors R₁-R₄. A new high-priority activityA2 (referenced generally as number 900(2)) has a correspondingconfiguration 902(2), with only one resource R₃. The resource managerdetermines that the higher-priority activity A2 has rights to theresource identified by descriptor R₃ and preempts the activity A1. Inthis case, the victim activity A1 elects to reduce it usage of theresource identified by descriptor R₃ and maintains control of theremaining resources identified by descriptors R₁, R₂, and R₄, at leastfor the time being.

FIG. 10 illustrates a case where the resource manager considers whetherit can satisfy an entire configuration of a new configuration prior toembarking on a course of preempting existing lower-priority activities.FIG. 10 shows an existing low-priority activity A1 (i.e., 1000(1)) witha configuration 1002(1) that lists a single descriptor R₁. Anotherexisting, but high-priority, activity A2 (i.e., 1000(2)) has aconfiguration 1002(2) listing a single descriptor R₂. A third activityA3 (i.e., 1000(3)) with a medium priority requests to be added. Thethird activity A3 has a configuration 1002(3) that lists two descriptorsR₁ and R₂.

In this case, the resource manager must allocate the resourcesidentified by the two descriptors R₁ and R₂ to satisfy the request ofnew activity A3. The resource manager could preempt the low-priorityactivity A1 to permit reallocation of the resource identified bydescriptor R₁ to the medium-priority activity A3, but this would onlysatisfy one resource. The resource manager further determines that thecurrent user of the other resource R₂ is the high-priority activity A2.Hence, the resource manager would not preempt the higher-priorityactivity in favor of the medium-priority activity. Since the resourcemanager cannot satisfy the entire configuration of new activity A3, theresource manager opts not to preempt the low-priority activity A1 andinstead notifies the consumer associated with the new activity A3 thatits request cannot be satisfied.

Fallback Configuration

The scenarios described in the preceding section assumed that theactivities had only one configuration. However, as illustrated in thegeneral resource management architecture of FIG. 2, each activity mayspecify multiple configurations. With multiple configurations, there maybe a situation in which the activity is preempted from using a resource,but may still continue processing using another configuration that doesnot require the preempted resource. Accordingly, a flexible adaptiveprocess may be able to complete its task in some alternate manner, usingan alternate set of resources. For example, instead of using a hardwarevideo decoder (a resource that is reallocated to a higher priorityactivity), the activity might alternatively employ an algorithm thatuses a software video decoder.

The alternate configurations may utilize different resources, which maynot be in conflict, or simply fewer resources. Usually, use of analternate configuration leads to a degradation in the quality of resultsproduced by the application. In this situation, the activity is said to“fallback” from a more preferred configuration to another, lesspreferred configuration. For instance, when an activity dynamicallychanges from a preferred configuration having a hardware video decoderto a fallback configuration having a software video decoder, thefallback configuration cannot decode to a full-screen sized image. Theoutput of the application is thus degraded in quality to a reduced-sizevideo image on the monitor.

With reference to FIG. 2, the resource management architecture 100facilitates flexible adaptation of activities 122 when resourceallocations are changed. Each activity 122 can contain multipleconfigurations 124(1), 124(2), etc., where each configuration representsan acceptable set of resources so that the process can make progress ifit has all of the resources in the configuration. The configurations 124are ranked in order of preference by the application or consumerprocess. When the resource manager 102 preempts an activity, theactivity is required to release or reduce usage of its resources. Afterthe resources are freed up, there are several possible courses ofaction. In one approach, the consumer associated with the preemptedactivity can ask the resource manager to reserve resources of anotherconfiguration. Another approach is for the resource manager 102 toautomatically attempt to reserve resources in the next-highest-rankingfallback configuration. The resource manager continues successivelythrough each fallback configuration until (1) finding a configurationthat can be satisfied with the currently available resources, or (2)discovering that no fallback configuration can be satisfied.

FIG. 11 illustrates a process for dynamically downgrading from a morepreferred configuration to a less preferred configuration as operatingconditions change. Such change might be induced, for example, as aresult of the priority-based policy in which the resource manager 102preempts a low-priority activity in favor of reallocating the resourcesto a high-priority activity. The steps in FIG. 11 are implemented by theresource manager 102 and will be described with additional reference toFIG. 2. The depicted process assumes that the resource manager 102 haspreempted an activity's use of one or more resources as a result, forexample, of the resource allocation process shown in FIG. 6. Thus, thevictim activity no longer has its preferred configuration available.

At step 1100, when the resource manager 102 preempts an activity, theresource manager 102 determines whether the victim activity 122 hasanother configuration 124. If no other configuration is specified in theactivity container 122 (i.e., the “no” branch from step 1100), theresource manager notifies the consumer (e.g., application 32) that noalternative configurations are specified and gives the consumer anopportunity to create a new configuration in the activity that describesa fallback set of resources and to request reservation of the newconfiguration (step 1102). Configuration creation is described abovewith reference to FIG. 3.

Alternatively, if one or more other configurations are noted in theactivity (i.e., the “yes” branch from step 1100), the resource manager102 proceeds through all fallback configurations 124 in the activity 122(step 1104). The resource manager 102 determines whether any of thefallback configurations can be satisfied (step 1106). If noconfiguration can be satisfied (i.e., the “no” branch from step 1106),the resource manager notifies the consumer and gives the consumer anopportunity to create a new configuration in the activity (step 1102).

Conversely, if at least one of the fallback configurations can besatisfied (i.e., the “yes” branch from step 1106), the resource manager102 reserves the resources in that configuration (step 1108). Theresource manager 102 also notifies the consumer that the fallbackconfiguration can be satisfied (step 1110). The notification takes placein such a way that if any non-preempted resource is in both the currentconfiguration and the fallback configuration, or if the preemptedresource is in both the current and the fallback configurations with thefallback configuration using a smaller quantity of the preemptedresource than the current one, the process can switch configurationswithout freeing that resource.

The fallback process of FIG. 11 supports three different approaches. Inone approach, the alternate configuration may not be created until theconsumer is notified that its current configuration is being preempted.This is demonstrated by step 1102 in FIG. 11. At this point, theconsumer (e.g., application 32) creates a new configuration without theconflicted resource(s) and tells the resource manager 102 to add thealternate configuration to the activity and reserve the alternateconfiguration. It may take some time to construct the alternateconfiguration, and communication with the resource manager (andindirectly with the providers) may take time as well. This time delaymay impact quality.

If all the resources in the fallback configuration are available, theresource manager 102 reserves the fallback resources and, if theconsumer so desires, release the original resources. Alternatively, theconsumer may temporarily own the union of the two configurations andexplicitly release the original resources later. If the fallbackconfiguration cannot be satisfied, the resources in the originalconfiguration are not released to let the process try again with yetanother fallback configuration. Eventually, if the consumer cannotcreate an acceptable fallback configuration, it stops processing andreleases the resources for reallocation to another activity. Theconsumer then waits until the resources become available again.

A variant on the first approach is where the consumer, on receiving itsnotification, explicitly notifies the resource manager that it can freethe resources that have been preempted. In this way, the resources mayget freed a bit sooner than waiting until the consumer is able to buildits fallback configuration.

In another approach, the alternate configurations are created in advanceby the resource consumer. This is illustrated by the “yes” branch fromstep 1100 in FIG. 11 and by the multiple configurations 124(1) and124(2) in one activity 122(1) in FIG. 2. As part of preemption, theresource manager 102 simply notifies a preempted consumer that it islosing its current configuration in the activity and must switch to thegiven fallback configuration. Prior to this notification, the resourcemanager reserves the resources in the fallback configuration, thus theconsumer temporarily owns the union of the two configurations. Theconsumer then frees the contested resource and makes necessary changesto support the alternate set of resources. The resource manager 102 thenreleases the resources in the original configuration that are not in thefallback configuration so that those resources may be reallocated toother activities.

It is noted that fallback configurations can also be used during initialreservation of resources. For example, when an application 32 suppliesmultiple configurations 124 in an activity 122, ranked by merit, theresource manager 102 picks the highest-ranking configuration that it cansatisfy and reserves those resources and notifies the process whichconfiguration was fulfilled.

FIG. 12 illustrates one scenario in a process of downgrading to a lesspreferred configuration. FIG. 12 shows an existing activity A1(referenced as number 1200(1)) and a new activity A2 (referenced asnumber 1200(2)) residing at the resource manager 102. The new activityA2 has a higher priority than that of the existing activity A1.

The existing activity A1 has two configurations: a preferredconfiguration C1 (referenced as number 1202 and marked with a letter “H”to designate it as being higher ranked), and a fallback configuration C2(referenced as number 1204 and marked with a letter “L” to designate itas being lower ranked). The preferred configuration C1 contains a set ofresources descriptors R₁, R₂, and R₃ to identify corresponding resourcesneeded to perform the activity. The fallback configuration C2 contains adifferent set of resources descriptors R₁ and R₄ to identifycorresponding resources needed to perform the activity. The new activityA2 has one configuration C1 (referenced as number 1206), which containsone descriptor R₃ to identify the corresponding resource.

In this illustrated example, resource descriptor R₃ identifies aresource provider R₃, referenced as number 104. Assume that the resourceprovider R₃ controls a resource that can only be allocated once, such asa tuner. Furthermore, assume that the counter 1208 maintained by theresource provider R₃ indicates that the sole tuner is currentlyallocated to the existing configuration C1 of the lower-priorityactivity A1.

When the resource manager 102 receives a reservation request from theconsumer that created the new activity A2, the resource manager 102learns that the resource provider 104 cannot allocate resources to theother activity, A1, any more. Thus, the resource manager determines thatit should preempt the lower-priority activity A1 to shift the resourceassociated with descriptor R₃ to the higher-priority activity A2.

The resource manager determines whether the lower-priority activity A1has an alternate configuration (i.e., step 1100 in FIG. 11). In thiscase, activity A1 has a fallback configuration C2 that does not requirethe preempted resource controlled by provider R₃. Thus, the resourcemanager 102 reserves the resources in the fallback configuration C2(i.e., resources provided by provider R₁ and R₄) and notifies theconsumer associated with activity A1 that it is being preempted andneeds to switch to the fallback configuration C2 (i.e., steps 1108 and1110 in FIG. 11.).

The activity A1 shifts to using the fallback configuration C2, asrepresented by arrow 1212. The resource manager 102 reallocates theresource of provider R₃ from the activity A1 to the new activity A2, asrepresented by arrow 1210.

Hopefully, the impact to the consumer associated with activity A1 willbe minor and the process may continue without disruption resulting fromthe conversion to the fallback configuration C2. For example, considerthe situation described above where the hardware video decoder is lost,but can be replaced by a software decoder. The application may have away to load and initialize the software video decoder and then integrateit into the video stream in a manner such that the video stream is notinterrupted.

The difference between configurations in the activities may vary widely.It may be that the original and alternate configurations have a greatdeal in common with respect to the resources required. Indeed, thedifference may be only in that the resource in conflict is removed fromthe alternate configuration. Alternatively, the configurations may bequite different.

Upgrade Notification

In the preceding section, the consumers in the system may be required tomove to a less desirable configuration in the event they are preemptedfrom a more desirable configuration. Upgrade notification involves thereturn trip by allowing consumers to upgrade to a more desirableconfiguration when resources once again become available.

FIG. 13 illustrates a process for dynamically upgrading from a lesspreferred configuration to a more preferred configuration as operatingconditions change. The process is implemented at the resource manager,and will be described with reference to FIG. 2. The depicted processassumes the application is running in a less desirable configurationbecause the application was either (1) unable to reserve all of thedesired resources in its highest ranking configuration when it initiallyrequested to reserve resources, or (2) previously preempted and moved toa lower-ranking configuration.

At steps 1300 and 1302, the resource manager 102 monitors the existingactivities to detect when an activity completes and releases itsresources. When resources are freed, the resource manager 102 examinesall activities, including activities that currently have noconfiguration reserved and activities with less-than-best configurationsreserved, to determine if it can upgrade to any more preferredconfigurations (step 1304). If so, the resource manager 102 sends anupgrade notification to the consumers associated with the activities(step 1306). The upgrade notification informs the consumer that a moredesirable (i.e., higher ranked) configuration in its activity can besatisfied with currently available resources.

The consumers register with the resource manager to receive upgradenotifications when a more desirable configuration than the one it iscurrently using becomes available. The upgrade notifications areoptional, however, and the consumers need not register to receive them.

When a consumer receives an upgrade notification, the consumer cansubmit an upgrade request to the resource manager asking to reserve theresources for the new configuration. Upon receiving the upgrade request,the resource manager attempts to reserve the new configuration (step1308). In one implementation, the resource manager essentially employsthe same process as illustrated in FIG. 3, except that the consumerbeing upgraded is permitted to reserve two configurations for a shorttime—the configuration it currently owns and the new configuration.Allowing the reservation of two configurations enables a smoothtransition from the old configuration to the new configuration. Theconsumer releases the old configuration after transitioning to the newone. In another implementation, the consumer application being upgradedmay be required to first shut down processing with the old configurationand then reserve the new one before resuming processing.

There is no guarantee, however, that the consumer will be successful inreserving the new configuration. For instance, it may be the case thatother higher-priority activities are also laying claim to the sameresources. The resource manager does guarantee that if the consumer'sattempt to upgrade to a more desirable configuration is unsuccessful,the consumer will retain the existing configuration.

It is noted that configurations, including higher ranking or lowerranking ones, may be added to an activity at any time, regardless ofwhether the activity has resources reserved. If a configuration is addedto an activity that currently has resources reserved, and if theconfiguration is of a higher ranking than the current configuration andthe higher ranking configuration can be satisfied, the resource managerwill send an immediate upgrade notification informing the consumer thatthe higher ranking configuration is possible.

FIG. 14 illustrates one scenario in a process of upgrading to a moredesirable configuration. FIG. 14 shows an existing activity A1(referenced as number 1400(1)), a waiting activity A2 (referenced asnumber 1400(2)), and a terminating activity A3 (referenced as number1400(3)) residing at the resource manager 102. The terminating activityA3 has the highest priority, followed by waiting activity A2, followedby the existing activity A1. The terminating activity A3 has completedits task and is in the process of releasing its resources designated bydescriptors R₁ and R₂.

The medium-priority activity A2 has a single configuration C1 thatrequires the resource designated by descriptor R₂. The medium-priorityactivity A2 is waiting because it was previously unable to gain accessto the resource that was allocated to the higher-priority activity A3.

The existing activity A1 has a preferred configuration C1, whichcontains a descriptor R₁, and a fallback configuration C2, whichcontains a descriptor R₄. The existing activity is currently using thefallback configuration C2, because the resource designated descriptor R₁is currently tied up by the higher-priority activity A3.

When the high-priority activity A3 terminates and releases the resourcesassociated with descriptors R₁ and R₂, the resource manager 102determines whether existing activities could benefit from the newlyreleased resources (i.e., steps 1304 and 1308 in FIG. 13). In this case,both activities A1 and A2 could benefit. Thus, the resource manager 102sends an upgrade notice to the applications 32(1) and 32(2) associatedwith the activities A1 and A2, respectively (i.e., step 1306). If theapplications elect to upgrade, they return upgrade requests. In thisexample, the resource manager 102 upgrades the configuration of activityA1 from the less preferred configuration C2 to the more preferredconfiguration C1, which utilizes the released resource designated bydescriptor R₁. This is represented by arrow 1402. The resource manageralso reserves the resource associated with descriptor R₂ on behalf ofactivity A2.

Configuration Building

As mentioned above, resources or resource providers may themselves, inaddition to providing a resource, be consumers of other resources thatare managed by other resource providers. For example, a USB cameraresource is a consumer of bandwidth that is provided by the USB driver.Thus, the USB driver is a dependent resource provider whose parent isthe USB camera resource. Yet, when an application asks for the USBcamera, it may not be aware that the camera needs to use the services ofthe USB driver. That is, some resource consumers, such as applications,may not be aware or knowledgeable of all of the dependent resources thatit needs to perform a task. These types of resource consumers might onlybe aware of the “top level” resources that they need to perform theirtasks. As an example of this type of resource consumer, considerapplications that are written prior to later-developed technology.Specifically, a television application may be written to request only a“tuner resource” from a tuner resource provider. Later developments intuner technology may make additional tuners available that were notavailable to the television application when it was originally written.These new tuners may be consumers of resources that themselves may havebeen developed or improved after the application was written. Yet, whenthe television application requests a “tuner resource”, there needs tobe a way to incorporate the new tuner resource and its dependentresources into one or more configurations so that the older applicationcan use the newer tuner. Advantageously, aspects of the describedembodiment enable this to be done in a manner in which each of theresource providers is aware of its own resource needs. Hence, when aresource provider is called upon during the configuration buildingphase, it can take all of the appropriate steps to ensure that itsdependent resources are adequately represented in the configurationsthat get built.

FIG. 15 shows an architecture that illustrates but one way in whichresources that are unknown to a resource consumer are nonethelessrepresented in the configuration that is being built. It should beunderstood that the description that is provided just below is tailoredfor the specific case in which a resource consumer is not aware of thedependent resources that are needed to perform a task. It is possiblethat the resource consumer might be knowledgeable about one or all ofthe dependent resource providers. In that case, the configurationdescribed just below would be built, for example, through a number ofdirect calls from the resource consumer to the resource providers. Forpurposes of this discussion, however, we will assume that such is notthe case.

The processing that is described just below takes place after one ormore of the configurations have been created, and corresponds to step306 (FIG. 3). Here, only one configuration 124(1) within one activity122(1) is illustrated. It should be apparent that multipleconfigurations within one or more activities could be built. At thispoint the configuration is unpopulated. When a configuration ispopulated, one or more resource descriptors are added to theconfiguration by each of the resource providers that contribute aresource to perform a particular task with which the activity isassociated. Each resource descriptor identifies its resource provider,and indicates a quantity of an associated resource that is needed for aparticular configuration. In this specific example, only one resourceconsumer is utilized and comprises an application 32(1).

In the illustrated example, application 32(1) is aware or knows of onlya subset of resources (and hence their associated resource providers)that are necessary for it to perform its task. Here, application 32(1)is aware of a first set of resource providers that includes resourceproviders 104(1) and 104(2). The application 32(1) is unaware and notknowledgeable of a second set of resource providers (i.e. resourceproviders 104(3) and 104(4)). These resource providers are used byresource provider 104(2) to assist it in performing the task. Each ofthe resource providers 104(1)-104(4) is configured to call otherresource providers when the configuration 124(1) is being populated.Since application 32(1) is aware of certain resource providers, itaccordingly calls only those resource providers so that the resourceproviders can provide information that enables the configuration 124(1)to be populated with resource descriptors that are associated with theresource providers. Those resource providers of which the application32(1) is unaware are called by other resource providers that use theirresources.

For example, in FIG. 15, the application is aware of resource providers104(1) and 104(2). Hence, when the application is attempting to populateor build a configuration, it directly calls these resource providers (asindicated by the arrows 1501 and 1502). In the described embodiment,function calls are made to the resource providers and identify theactivity (e.g. via an activity ID or handle) and a configuration (e.g.via a configuration handle or ID) that is being populated. Responsive toreceiving these function calls, each of the resource providers make afunction call on the resource manager 102 and provides it withinformation regarding its associated resource. The resource manager 102then uses this information to maintain the configuration. In theillustrated example, such information is provided in the form ofassociated resource descriptors. In this example, each of resourceproviders 104(1) and 104(2) provide the resource manager 102 with theinformation required to construct the resource descriptors R₂ and R₄respectively. This is indicated by the arrows 1503, 1504 originatingwith each of the respective resource providers and terminating at theresource manager 102. As the application is unaware, however, of theresource providers 104(3) and 104(4), it does not call them directly.Rather, in this example, the parent resource provider that utilizestheir resources calls them. Hence, resource provider 104(2) calls (arrow1506) resource provider 104(3) and hands it the activity handle and theresource identifier for its resource descriptor in the configurationthat is being populated. Responsive to this call, the resource provider104(3) calls (arrow 1508) the resource manager 102 (as indicated by thecommunication arrow designated R₃) with the information that theresource manager needs to maintain the configuration. This informationincludes so-called relationship information concerning resource provider104(2). In this example, the relationship information describes achild/parent relationship that resource provider 104(3) has withresource provider 104(2). Similarly, because resource provider 104(3)uses resources associated with resource provider 104(4), it calls (arrow1510) resource provider 104(4) with the activity handle and resourceidentifier for its resource descriptor in the configuration that isbeing populated. In turn, resource provider 104(4) calls (arrow 1512)the resource manager with information (including relationshipinformation that describes its parent) so that the resource manager canmaintain the configuration. This communication is illustrated by thecommunication arrow designated R₁.

In this example, the nature of the parent/child relationship is shown bydescriptors 126 that are arranged in and comprise a hierarchical treethat describes the dependent relationships of certain resources.Although the described configuration is in the form of a hierarchicaltree, other configurations, including ones that are not necessarilyhierarchical in nature could be used, e.g. flat or linearconfigurations, or configurations that do not describe resourcedependencies. It is, however, advantageous to utilize a hierarchicalstructure in the event that particular conditions occur. Examples ofthese particular conditions include the failure of a resourcereservation, or a preemption of a resource, each of which are discussedin more detail below.

FIG. 16 shows steps in an exemplary resource management method inaccordance with the embodiment described just above. Step 1600 calls aresource provider. In the illustrated example, this call is made to aninterface that is supported by the resource provider and used when oneor more configurations are desired to be built or populated. The call tothe resource provider can come from a resource consumer (such as anapplication or system component), or from another resource provider.Step 1602 receives the call and responsive thereto, the resourceprovider supplies information (step 1604) regarding its resource that isutilized to maintain the configuration that is being populated. Step1606 determines whether the resource provider depends on any otherresource providers in order for a task to be performed. In systems wherethe resource consumer is unaware of dependent resource providers, thisdetermination is made by the individual resource providers. In systemswhere the resource consumer is aware of dependent resource providers,this determination can be made either by the resource consumer or theindividual resource provider. In the example of FIG. 15, thedetermination for resource provider 104(1) would be negative, so step1608 would determine whether there are any additional calls to otherresource providers. If there are, step 1608 branches to step 1602 andcontinues as described above. If there are no more additional calls tobe made for the particular configuration, then step 1610 either gets thenext configuration or activity and repeats the processing describedabove, or quits. If step 1606 determines that there is one or moredependent resource providers, step 1612 calls the dependent resourceprovider or providers. Accordingly, when a resource provider is called,it is programmed to know which other resource providers to call. In theFIG. 15 example, when the application calls resource provider 104(2),the resource provider knows to call resource provider 104(3) (step1606). Accordingly, it calls resource provider 104(3) and hands it theactivity handle and resource identifier for its resource descriptor inthe configuration that is being populated. Responsive to receiving thiscall, resource provider 104(3) supplies additional information (step1616) regarding its resource that is used to build or populate theconfiguration. Step 1616 then branches back to step 1606 and determineswhether there are any additional dependent resources. This step can beperformed either by resource provider 104(2) (in the event it depends onmore than one resource provider) or by resource provider 104(3) (in theevent that it depends on a resource provider). In this particularexample, this step is performed by resource provider 104(3) becauseresource provider 104(2) only depends on one resource provider. In thisparticular case, since resource provider 104(3) depends on resourceprovider 104(4), processing would proceed through steps 1612-1616 and,depending on whether there were any additional calls, would eitherproceed to step 1602 or 1610.

In the illustrated example, information is received from a plurality ofdifferent resource providers and utilized to build a configurationcomprising a hierarchical tree. The tree is maintained by the resourcemanager 102 and utilized to make reservations and promulgate errornotifications.

Error Notifications

After one or more configurations have been built for one or moreactivities, the resource manager 102 can attempt to reserveconfigurations for the activities. Exemplary processes for doing thisare described in detail above. During the course of trying to reserveconfigurations, it is possible that one or more resources cannot bereserved. In that case the reservation fails and the resource is notavailable. When this happens, it is desirable to notify the resourceconsumer of the failed reservation. One reason for this is that theresource consumer may, once informed, attempt to construct or reservealternate configurations. Another reason for this is that the resourceconsumer might be presented with various options, i.e. other resourcesettings, that might allow the resource consumer to perform its task.

Notifications, however, pose some challenges in embodiments where theresource consumer is not aware of a dependent resource that has failedor been preempted. For example, and with reference to FIG. 15, if duringthe course of trying to reserve the resource associated with resourceprovider 104(4) the reservation fails, the error message that isgenerated by the resource provider 104(4) will typically containproprietary terms that would not be understood by the resource consumer.Thus, there needs to be a way for the failure to be articulated to theresource consumer in an intelligible way. In the embodiment thatutilizes the hierarchical tree configuration, the error reporting isaccomplished by simply following the chain of resource dependenciesuntil a resource provider is found that the resource consumerrecognizes. The error is then reported to the resource consumer throughthe recognized resource provider. During this process, the error messagethat is initially promulgated by the dependent resource provider isreceived in its proprietary form by its parent resource provider,translated into a form that is understood by the next in line resourceprovider and forwarded accordingly. Ultimately, what reaches theresource consumer is an error notification that is presented in termsthat are understood by the resource consumer.

As an example, consider the following: An application tries to reserve aUSB camera resource so that it can be played at 30 frames/second.Although the camera resource may be available, assume that there is notenough USB bandwidth to accommodate the 30 frames/second. The failurethat gets generated is generated by the USB bandwidth resource providerand is defined in proprietary terms that are not understood by theapplication. Thus, the failure from the USB bandwidth provider isreported to its parent—the USB camera resource provider. The USB cameraresource provider translates the failure to the form reported to theapplication.

Error reports to the resource consumer may take different forms. Forexample, an error report might simply report that a known resource, e.g.the camera resource, is presently unavailable. Alternately, the errorreport can present one or more options to the resource consumer in theevent of a failure. For example, where a USB camera resource fails dueto a shortage of USB bandwidth, the USB bandwidth resource providermight give the USB camera provider the bandwidth it has available. TheUSB camera resource provider could then translate this information to aform that the application understands and give it an option of a reducedframe rate (e.g. 5 frames/second) or a reduced window size. In thisinstance, the task would still be capable of being performed, albeitwith a different allocation of resources. Although the above example isgiven in terms of a reservation failure, the same error reportingexample applies when a resource is preempted for use by anotheractivity.

The error report may, however, have another effect. Specifically, someresource providers can be programmed to attempt to remedy or troubleshoot particular problems that might arise and cause failures. In thisinstance, it would not be necessary to report the error to the resourceconsumer. Trouble shooting can occur at any place in the chain ofdependencies. For example, consider a resource provider that manages ahardware device. Assume that the hardware device is not availablebecause of a preemption. The resource provider, rather than promulgatingan error report to the resource consumer, might provide a “virtualdevice” that looks to the resource consumer as if it is the realhardware device. The resource consumer would then unknowingly use thevirtual device until the real hardware device became available. In thismanner, no error is reported to the resource consumer and the task canstill be performed.

Using the hierarchical tree configuration makes error reporting muchmore efficient than a flat or linear configuration because of itsimplicit ordering. Although using a flat or linear configuration ispossible, it is less desired.

FIG. 17 describes steps in an error reporting method in accordance withthe described embodiment. Step 1700 represents resources as ahierarchical tree structure. Specific examples of how this can be doneand exemplary structures are given above in the “Configuration Building”section. Step 1702 detects a particular condition that is associatedwith a particular resource. In this example, the particular condition isan error condition and step 1702 can be performed by the resourcemanager 102 (FIG. 15) because it is programmed to know when there is areservation failure or a preemption. This is because the resourcemanager runs the resource calculations and determines resourceconflicts. Step 1704 then notifies the resource provider that isassociated with the resource. To do this, the resource manager callsback into each provider (i.e. providers set up a call back when theyregister). The resource manager gives the current error packet(initially it is empty) to the provider and then receives back from theprovider a translated packet. This translated packet is then handed offto the next provider in the chain and so on. One of the providers mayfix the error itself, in which case the packet does not have to beforwarded any further up the chain.

Policy Manager

A policy manager, in association with the resource manager, determineswhich applications will be allowed to access and use the limitedresources when more than one application vies for the same resource. Theapplications themselves do not initiate and utilize the resources oftheir own accord, nor do the applications control the priorities of theresource managed activities. Rather, the resources are allocated by theresource manager based on the policies established at the policymanager.

There are possible different types of policies. One set of policies, forexample, may be used in conjunction with priority-based conflictresolution, which determines resource allocation based upon whichapplications and/or users have priority over others to use theresources. The term “priority” is not used in the sense of a traditionalthread or process priority, but in the context of an arbitration policybetween consumers contending for the same resources. Priorities are notassigned to individual resources, but rather are assigned to theactivities established at the resource manager by the applications.

The policies determine which activities are “more important” or “lessimportant” in some way (e.g., “more important” to the user) incomparison to other activities. This allows the resource managementarchitecture to transfer desired, but limited, resources from the lessimportant activities to the more important activities.

Another viable policy is “first reservations wins”. By following thispolicy, the resource manager would reserve resources for activities on afirst-come-first-served basis.

Another possible policy is “most recent reservations win”. With thispolicy, the resource manager attempts to reserve resources for theactivities that most recently sought reservation.

Other possible policies include resource sharing to achieve some type ofbalance or cooperation guidelines, user-specified winners in which theuser picks which activities are more important, and so forth.

The resource management architecture 100 shown in FIG. 2 implements aresource manager 102 that makes resource allocation decisions based onpolicies established by a separate and independent policy manager 108.The policy manager 108 determines, independently of the applications,which activities should get access to resources when there is a conflictsuch that not all activities can be allocated the resources. The systemor user sets the policies 110 and the policy manager 108 translates theminto absolute priorities.

FIG. 18 shows one exemplary policy management architecture 1800 thatillustrates utilizing the policy manager 108 in conjunction with theresource management architecture 100. The resource manager 102 exposes adefined API (application program interface) 120 to accept requests forresources from the applications 32(1)-32(A). One API is described belowin detail under the heading “Resource Manager API”. When an application32 wants to perform a task, it uses the API 120 to create an activity122 at the resource manager 102. An activity is a data structureassociated with a task being performed in the system. One activityexists per task being performed. The resource manager 102 is showncontaining activities 122(1)-122(N) created by the applications32(1)-32(A).

The policy management architecture 1800 is implemented in software, andin this example, includes the policy manager 108 having components atboth the user level and the kernel level. The policy manager 108 has auser component 1802, a kernel component 1804, and an interaction buffercomponent 1806. The policy manager interaction buffer 1806 holdsnotifications between the policy manager kernel component 1804 andpolicy manager user component 1802.

A policy manager user interface 1808 resides at the user level and isexternal to the policy manager 108. The policies are initially createdwithin the system, yet are designed to be flexible so that a user canoptimize the system by customizing the policies as well as adjusting howthe policies are interpreted and used by the policy manager 108. Throughthe user interface 1808, a user can define policies and establish theorder in which policies will be applied to resolve resource reservationconflicts between applications vying for the same resource.

The policy manager kernel component 1804 is an interface between thepolicy manager 108 and the resource manager 102 to control activitypriorities and priority modifications. The policy manager kernelcomponent 1804 opens a resource management defined call-back object andregisters a call-back routine The resource manager 102 uses thecall-back object to notify the policy manager 108 of an activity eventat the resource manager 102.

The policy manager user component 1802 is implemented by threecomponents: (1) the aforementioned policies component 110, (2) a policymanager dispatch engine 1810, and (3) an activity list 1812. Thepolicies component 110 maintains the policies used to make resourceallocation decisions and the policies used to resolve resourceallocation conflicts. The policies maintained in the policy component110 include a fixed priority policy 1814, a focus based policy 1816, anda user resolution policy 1818. The policies are applied to resolveresources conflicts in the order indicated by the policy enumerations(1)-(3); i.e., if a resource conflict cannot be resolved using the fixedpriority policy 1814, enumerated as (1), then policy (2), the focusbased policy 1816, will be applied, and so on.

The policies utilize activity-specific information that applications 32provide to prioritize the system activities. The applications 32 providethis information by setting policy attributes for the activities. Theinformation is provided via an API set that creates, deletes, modifies,and retrieves the policy attributes. This API set is an extension of theRMU API described below in detail under the heading “Resource ManagerAPI”. The specific API set is described below under the heading“Extension to the RMU API”.

The resource manager 102 notifies the policy manager 108 of an activityevent when activities 122 are created or destroyed, and when resourcesare reserved or unreserved for an activity configuration. The policymanager 108 is also notified when there is a resource reservationconflict between activities and when the process of a user interactiveapplication attains system focus.

The policy manager dispatch engine 1810 receives the activity eventnotifications from the resource manager 102, via the policy managerkernel component 1804 and interaction buffer component 1806, and thendispatches the notifications to the policies 110 for further action. Thepolicy manager dispatch engine 1810 determines the absolute activitypriorities after the activities have been “graded” by the policies 110.The policy manager dispatch engine 1810 also maintains a list of all ofthe policies as well as the activity list 1812 with the associatedpriority of each activity.

More specifically, the policy manager dispatch engine 1810 receives theactivity event notifications from the resource manager 102 whenapplications call the methods RMCreateActivity, RMDestroyActivity,RMReserveResources, and RMUnreserveResources. Upon receiving the eventnotifications, the policy manager dispatch engine 1810 updates theactivity list 1812 and sends the notifications to the policies 110. Thepolicies 110 can trigger a reprioritization of the activity datastructures such that the activity list is reprioritized according to therelative importance ordering of the current activities in the system.

The activity list 1812 is an object used by the policy manager dispatchengine 1810 to pass a list of current activities to the policies 110 forpriority ordering of the activities. The activity list 1812 is passed asa collection of activity information objects containing all of theactivities 122. The policies 110 modify the collection of activityinformation objects into sub-sets of activities in priority order.Activities in the same sub-set receive the same absolute priority whenthe policy manager dispatch engine 1810 determines the absolute activitypriorities after the policies 110 have completed grading the activities122.

The fixed priority policy 1814 determines activity priorities based onuser-defined importance ordering of activity categories. For example, auser can define the following activity categories as having a particularorder of importance:

Existing Activities Category Category Importance A1 Watching DVD₁ C1 1A2 Watching TV C2 2 A3 Watching DVD₂ C3 3 New Activity Category CategoryImportance A4 Recording C2 2

Activities A1-A3 are existing at resource manager 102. When a newactivity A4 is created, the resource manager 102 notifies the policymanager 108 of an activity event. The policy manager dispatch engine1810 updates the activity list 1812 and passes the list of currentactivities 122 to the policies 110 for priority ordering of theactivities 122. The fixed priority policy 1814 modifies the activitylist 1812 into sub-sets of activities in priority order:

Priority Set Activities 1 A1 2 A2, A4 3 A3

The focus based policy 1816 determines activity priorities based on thefocus history of the processes that have created resource managementactivities 122. Only user interactive applications require a focus basisfor maintaining a focus history. Thus, the focus based policy 1816prioritizes those activities 122 created by user interactiveapplications. When the process of a user interactive application gainsfocus, the process's activity is identified first in the focus history.

From the example above, a user has defined activities A1-A4 as having aparticular order of importance, whereupon the fixed priority policy 1814determined to which priority set each activity belonged. If the userbegins watching TV (activity A2, priority 2) and recording (activity A4,priority 2) is subsequently scheduled to occur, the resource manager 102must determine to which activity it should allocate the system's onetuner resource. The focus based policy 1816 would identify the processof presenting the image from TV as first in the focus history when theuser began watching TV. Accordingly, activity A2 would have focuspriority in Priority Set 2:

Priority Set Activities 1 A1 2 {circle around (A2)}, A4 3 A3

The user resolution policy 1818 resolves a resource reservation conflictwhen the resource manager 102 is unable to resolve a conflict based oncurrent activity priorities. For example, a user may have scheduled tworecording activities to record two different channels starting at thesame time:

Existing Activities Category Category Importance A1 Record A C1 1 A2Record B C1 1Initially, the fixed priority policy 1814 would determine the activitypriorities and policies 110 would modify the activity list 1812 intopriority sub-sets of the activities:

Priority Set Activities 1 A1, A2Given that both activities A1 and A2 have the same priority to the user,a resource conflict occurs when the resource manager 102 must determineto which activity it should allocate the system's one tuner resource.The focus based policy 1816 cannot resolve the conflict because neitherRecord A nor Record B is a process having gained the system focus.

Upon receiving information from the policy manager dispatch engine 1810that a conflict exists between activities A1 and A2, the user resolutionpolicy 1818 communicates with the user via the policy manager userinterface 1808 for a resolution of the conflict. When the userre-prioritizes the activities, the policy manager policies 110 modifythe activity list 1812 to reflect the user's resolution choice. The userresolution policy 1818 also maintains a user resolution history for allactivities over their lifetime to reduce the necessity of userinteraction to resolve resource conflicts.

FIG. 19 shows steps in a method for the policy management of activitiescreated at the resource manager 102. At step 1900, the policy managerdispatch engine 1810 receives an activity notification from the resourcemanager 102. The policy manager 108 is notified for activity creation,activity destruction, activity reservation, activity unreserve, and fora resource reservation conflict.

Upon receiving an activity notification, the policy manager dispatchengine 1810 updates the activity list 1812 (step 1902). The policymanager dispatch engine 1810 then forwards the activity notification tothe policies 110 (step 1904).

At step 1906, the policies 110 determine whether the activitynotification (step 1900) was for a resource reservation conflict betweentwo or more activities. If the policies need to resolve a conflict(i.e., the “yes” branch from step 1906), then the policies determine therelative importance of the conflicting activities (step 1908). This mayinvolve consulting with the user via the user resolution policy 1818 asdescribed above.

After determining the relative importance of the conflicting activities(step 1908), or if the policies do not need to resolve a conflict (i.e.,the “no” branch from step 1906), the policies determine whether activityreprioritization is required (step 1910). Typically, activityreprioritization is required for activity creation and activityreservation. Activity reprioritization is typically not required foractivty destruction or activity unreserve.

If activity reprioritization is not required (i.e., the “no” branch fromstep 1910), then the policy manager 108 does not need to update theresource manager 102 of the activities' priorities and the method isended (step 1912). If activity reprioritization is required (i.e., the“yes” branch from step 1910), then the policies 110 reprioritize theactivities (step 1914). After the activities have been reprioritized,the policy manager dispatch engine 1810 determines the absolutepriorities of the activities (step 1916). The policy manager dispatchengine 1810 then updates the resource manager 102 of the priorities ofthe activities (step 1918).

The above examples assume that the policies work together with prioritybased conflict resolution. However, in other situations, there may be nopriority amongst the resource consumers. That is, the activitiesassociated with the applications may have equal priority or no priorityat all.

Consider the following scenario. Activity A1 has two configurations C1and C2. The most preferred configuration C1 requires two resources R₁and R₂. The less preferred configuration C2 utilizes only one resourceR₁. Activity A2 has two configurations: (1) a most preferredconfiguration C1 which utilizes two resources R₁ and R₂ and (2) a lesspreferred configuration 62 which utilizes only one resource R₂.

An attempt to simultaneously run the preferred configurations ofactivities A1 and A2 results in a conflict. In this situation, theresource manager might elect to execute the second configurations forboth activities, which allows the two activities to continuesimultaneously. Since there is no priority distinction betweenactivities A1 and A1, there is no need to execute one activity at theexpense of the other.

Another set of policies may involve running as many activities aspossible, with each activity using a less preferred configuration,rather than running fewer activities with their most preferredconfigurations. For example, in the above scenario, even assuming thatactivity A1 has a higher priority than activity A2, the policy managermight prefer to run both of them using their secondary configurationsrather than only performing activity A1 using its best configuration.

Following are exemplary methods utilized in association with the policymanagement architecture.

Methods in the CPolicyManager Class

1. void Reprioritize( )

a) Description

This method is exposed by the main policy manager dispatch engine(CPolicyManager) so that policies can trigger a reprioritization ofactivities. For example, the focus policy would use this method totrigger a reprioritization of activities whenever focus changes to anapplication which has created an activity in the resource manager. Thismethod would post a notification in the policy manager dispatch engineand then return. As a result of this notification, the policy managerdispatch engine would call CPolicyManager::CalculatePriorities( ) whichwould hand the activity list to the policies for reprioritization.

b) Return Value

None.

2. HRESULT CalculatePriorities( )

a) Description

This method is used to calculate priorities for all activities in thesystem. This method would call CPolicy::CalculatePriorities( ). Theresulting compartmentalized activity list would then be used tocalculate the absolute priorities of the activities which would then beset in the resource manager.

b) Return Value

S_OK if successful.

E_FAIL otherwise.

3. CActivityList*GetActivityList( )

a) Description

This method will be used by the policies to get the list of currentactivities in the system. This would be used, for example, by the focusbased policy when it initializes to get the current list of activitiesin the system so that it could start maintaining the focus history forthe processes which have a resource manager activity associated withthem.

b) Return Value

A pointer to the CActivityList object, which exposes methods such thatthe activities in the system can be enumerated.

4. void OnNewActivity(PRM_ACTIVITY Activity)

a) Description

This method will be called by the policy manager dispatch engine when itreceives notification from the resource manager that a new activity hasbeen created. This method would create a new CActivity object whichreflects the activity created in the resource manager and then pass onthis notification to all of the policies by callingCPolicy::OnNewActivity( ). The policies can then process thisnotification and trigger a reprioritization if necessary.

b) Parameters

Activity—A structure of type PRM_ACTIVITY as defined in the appendix.The structure contains the activity handle and the owning process id.

c) Return Value

None.

5. void OnDestroyActivity(PRM_ACTIVITY Activity)

a) Description

This method will be called by the policy manager dispatch engine when itreceives notification from the resource manager that an activity hasbeen destroyed. This notification would be passed on to all of thepolicies using CPolicy::OnDestroyActivity( ). The activities can usethis to clean up their private information or trigger a reprioritizationif necessary.

b) Parameters

Activity—A structure of type PRM_ACTIVITY as defined in the appendix.The structure contains the activity handle and the owning process id.

c) Return Value

None.

6. void OnReserve(PRM_ACTIVITY Activity)

a) Description

This method will be called by the policy manager dispatch engine when itreceives notification from the resource manager that reservation for anactivity configuration has been completed. This notification would bepassed on to all of the policies using CPolicy::OnReserve( ).

b) Parameters

Activity—A structure of type PRM_ACTIVITY as defined in the appendix.The structure contains the activity handle and the owning process id.

c) Return Value

None.

7. void OnUnreserve(PRM_ACTIVITY Activity)

a) Description

This method will be called by the policy manager dispatch engine when itreceives notification from the resource manager that un-reservation foran activity configuration has been completed. This notification would bepassed on to all of the policies using CPolicy::OnUnreserve( ).

b) Parameters

Activity—A structure of type PRM_ACTIVITY as defined in the appendix.The structure contains the activity handle and the owning process id.

c) Return Value

None.

8. HRESULT OnConflict(PRM_ACTIVITY conflicting Activity,PRM_ACTIVITY*victimArray, ULONG ulNumVictims)

a) Description

This will be called when the resource manager is unable to resolve aresource conflict using current activity priorities. This method wouldthen call CconflictPolicy::OnConflict( ) to get a resolution for theconflict. Upon resolution of the conflict, the new activity prioritieswould be set in the resource manager by the policy manager dispatchengine.

b) Parameters

conflictingActivity—is the activity that caused a resource conflict onreservation. It is a structure of type PRM_ACTIVITY as defined in theappendix. The structure contains the activity handle and the owningprocess id.

VictimArray—Array of PRM_ACTIVITY structures which are the victimactivities.

UINumVictims—Number of victim activities.

c) Return Value

S_OK if conflict is resolved by the policy.

E_FAIL otherwise.

Methods in the Cbasepolicy Class

1. virtual HRESULT GetPolicyName(LPTSTR*pBuffer, ULONG*pBufSize)=0

a) Description

Get the name for the policy.

b) Parameters

PBuffer—pointer to the buffer in which the name will be copied whosesize is specified by ulBufSize.

pBufSize—size of the buffer. The size of the policy name would be copiedonto.

c) Return values

S_OK if successful.

E_OUTOFMEMORY if not enough memory is available in which case therequired size would be copied into pBufSize.

E_FAIL otherwise.

2.

virtual void OnNewActivity(CActivity *pActivity) virtual voidOnDestroyActivity(CActivity *pActivity) virtual voidOnReserveActivity(CActivity *pActivity) virtual voidOnUnreserveActivity(CActivity *pActivity)

a) Description

These are the notification methods that are called by the policy managerdispatch engine (CPolicyManager) upon receiving notifications from theresource manager. Policies can trigger a reprioritization on thesenotifications by calling CPolicyManager::Reprioritize. They can alsoupdate their private information using these notifications. For example,the focus policy would add the new activity to its focus historytracking when its OnNewActivity( ) is called.

b) Parameters

PActivity: pointer to the CActivity object which contains the activityhandle, the owning process id and other activity specific information.

c) Return Value

None.

Methods in the Cpolicy Class (in Addition to Methods in CBasePolicy)

1. virtual HRESULT CalculatePriorities(CBucketList*pBucketList)=0

a) Description

This method will be called by the policy manager dispatch engine(CPolicyManager) to calculate priorities for activities in the system.The bucket list would initially contain a single bucket with all theactivities in the system when this method is called on the first policy.The policy would then compartmentalize this bucket list. Thecompartmentalized bucket list would then be passed on to other policiesby the policy manager dispatch engine for further processing.

b) Parameters

PBucketList: Pointer to the CBucketList object which is a list ofbuckets containing activity objects.

c) Return Value

S_OK if successful.

E_FAIL otherwise.

Methods in Cconflictpolicy Class (in Addition to the Methods inCBasePolicy)

1. virtual BOOL OnConflict(CActivity*pConflictingActivity,CActivityList*victimActivityList)=0

a) Description

This method will be called by the policy manager dispatch engine(CPolicyManager) when the resource manager is unable to resolve aresource conflict using current activity priorities. This method wouldresolve the conflict by determining if the conflicting activity is moreimportant than all the activities in the victim list or otherwise.

b) Parameters

ConflictingActivity—activity causing the conflict during reservation.

VictimActivityList—a list of victim activities that would need to giveup resources to satisfy the reservation by the conflicting activity.

c) Return values

TRUE if pConflictingActivity is more important than all the activitiesin the victim list.

FALSE otherwise.

Extension to the Resource Manager API

1.

HRESULT SetPolicyAttribute( IN HANDLE hActivity, IN LPTSTR pAttrName, INDWORD dwType, IN LPBYTE pData, IN DWORD cbData)

a) Description

Method used to add a policy attribute to the policy database. Theapplication can specify policy attributes using the handle to theactivity it received from RMCreateActivity( ).

b) Parameters

hActivity—Handle to the activity returned by RMCreateActivity( ).

pAttrName—pointer to a buffer that contains the name of the policyattribute, including the terminating null character.

dwtype—a DWORD code that indicates the type of data stored in thespecified value. For a list of possible type codes, see Registry ValueTypes in the Platform SDK documentation.

pdata—pointer to a buffer that contains the data for the specifiedvalue.

cbData—size of the pData buffer.

2.

HRESULT GetPolicyAttribute( IN HANDLE hActivity, IN LPTSTR pAttrName,OUT LPDWORD lpType, OUT LPBYTE pData, OUT LPDWORD lpcbData)

a) Description

Method used to retrieve a policy attribute to the policy database.

b) Parameters

hActivity—Handle to the activity returned by RMCreateActivity( ).

pAttrName—pointer to a buffer that contains the name of the policyattribute, including the terminating null character.

lpType—a pointer to a variable that receives the code that indicates thetype of data stored in the specified value.

pData—pointer to a buffer that receives the data for the specifiedvalue.

lpcbData—size of the pData buffer that is returned.

Architecture with Intelligent Interface Component

The resource management architecture 100 illustrated in FIG. 2 assumesthat the applications 32 are sufficiently intelligent to request theresources needed to complete a task. In some cases, however, it may bedesirable that the applications not have full or any knowledge of theresources they need. Moreover, the resource management architecture 100may be implemented in an environment where there are legacyapplications. In such situations, it is desirable that the legacyapplications be able to utilize the resource management architecture,even though the application may not know such an architecture exists.

FIG. 20 shows a resource management architecture 2000 that is similar tothat of FIG. 2, but includes an intelligent interface component 2002that intercedes on behalf of the applications to request resources. Theintelligent interface component 2002 may be a kernel-level component (asshown) or a user-level component.

With the inclusion of the intelligent interface component 2002, theapplications 32 need not know what resources they need to complete atask. For instance, suppose an application 32(1) is a TV application.The TV application may be concerned with how to present streamingcontent on a display, but have little care for how the streaming contentis received and displayed in the first place. That is, the TVapplication may not be fully aware that a particular tuner, decoder, andfilter are needed to receive and display the TV programming.

In such cases, the interface component 2002 is designed to understandwhich resources are needed for a generic level activity, such asdisplaying television. Thus, when the application 32(1) is launched, itcalls to the interface component 2002 to request playing of the TVprogramming. The interface component 2002, in turn, interacts with theresource manager 102 to create the activities and build theconfiguration(s) of tuning, decoding, and filtering resources needed toplay the programming. At this point, the interface component 2002essentially acts as the consumer in its dealings with the resourcemanager for purposes of requesting reservation of the resources, asdescribed above with respect to the process of FIG. 3.

Architecture with Schedule and Stateless Providers

In the resource management architecture 100 illustrated in FIG. 2, theresource providers 104 may have some idea to which activity it iscurrently allocated, the quantity of the resource that has beenallocated, as well as the concept that it is being allocated now.However, this need not be the case. Instead, the resource providers maybe configured without any knowledge of the owning application orallocated resource quantities. This information is maintained by theresource manager 102 on behalf of the resource providers 104. In thisconfiguration, the resource providers are said to be “stateless”. Onereason the use of stateless resource providers is beneficial is that itallows the architecture to evaluate possible configurations that may berequested in the future.

FIG. 21 shows a resource management architecture 2100 that differs fromthe architecture of FIG. 2 in that the resource providers 2102(1),2102(2), . . . , 2102(P) are stateless. The stateless resource providersare configured with no concept of time and hence, have no idea whetherthey are being requested now or in the future. The resource providers2102 are only concerned with what resources and how much of them arebeing used at any given request and this information is supplied to themby the resource manager.

The architecture 2100 also includes a scheduler 2104 to scheduleallocation of a set of the resources at a later time. The scheduler 2104includes a calendar to track the time of day and date. The scheduler2104 is configured to run “what if” scenarios to determine whetherresources controlled by the stateless resource providers 2102 will beavailable at selected times. For example, suppose the scheduler 2104mocks up one or more configurations of resources that are representativeof system usage at a prime time, such as 8:00 PM. The scheduler 2104then asks the resource providers 2102 whether they could allocateresources to these configurations. Since the providers have no conceptof time and the state data on which they have to base their decisions ishanded to them by the resource manager, they simply indicate whetherthey could meet such a collection of configurations.

Resource Manager API

The following is an exemplary API for the resource manager. The APIcalls described below are available in kernel mode The resource managerAPI includes a provider interface (Section A) and a consumer interface(Section B).

A. Provider Interface

Provider API Calls

1. RmRegisterResource

a) Prototype

NTSTATUS RmRegisterResource ( IN LPCGUID ResourceType, INPUNICODE_STRING ResourceName, IN PVOID ProviderContext, IN ULONGAccumulatorSize, IN RM_PROVIDER_CALLBACK CallbackTable, OUT PRM_HANDLEResourceHandle );

b) Description

Resource providers use this function to register resources. Eachprovider should call this function once for each resource typesupported.

c) Parameters

ResourceType: Pointer to a resource type GUID, describing the type ofthe resource.

ResourceName: Unicode string specifying a user-readable name for theresource.

ProviderContext: Pointer to provider context. This context pointer willbe passed back to the provider in all callbacks from the resourcemanager.

AccumulatorSize: Size in bytes of the resource accumulator buffer.Whenever the resource manager needs to create a resource accumulator, itwill allocate this amount of memory on behalf of the resource provider.

CallbackTable: A pointer to a structure containing pointers to callbackfunctions through which the resource manager will call back into theprovider. This structure is defined as follows:

typedef struct_RM_PROVIDER_CALLBACK { USHORT Version; USHORT Size;PRM_PROVIDER_ACCUMULATOR_ADD AccumulatorAdd;PRM_PROVIDER_ACCUMULATOR_INIT AccumulatorInit;PRM_PROVIDER_ACCUMULATOR_FREE AccumulatorFree;PRM_PROVIDER_ACCUMULATOR_COPY AccumulatorCopy;PRM_PROVIDER_RESERVE_NOTIFY NotifyOnReserve;PRM_PROVIDER_UNRESERVE_NOTIFY NotifyOnUnreserve;PRM_PROVIDER_REMOVE_NOTIFY NotifyOnRemove; } RM_PROVIDER_CALLBACK,*PRM_PROVIDER_CALLBACK;

The callback structure fields are as follows:

-   -   Version: The version of the interface. The provider must set        this to RM_VERSION_NUM before calling RmRegisterResource.    -   Size: The size of the structure. The provider must set this to        sizeof(RM_PROVIDER_CALLBACK) before calling RmRegisterResource.    -   AccumulatorAdd: Callback into the provider to be called to add        resource attributes to a resource accumulator. If the addition        does not cause a resource overallocation, AccumulatorAdd should        update the accumulator and return STATUS_SUCCESS. If the        addition does cause a resource overallocation, the provider        should return STATUS_RESOURCE_UNAVAILABLE, with the buffer left        in an undetermined state. Any other error should return an        appropriate error code.    -   The prototype for the AccumulatorAdd function is as follows:

NTSTATUS AccumulatorAdd ( IN PVOID ProviderContext, IN PVOIDAttributeBuffer, IN OUT PVOID Accumulator );

-   -   AccumulatorInIt: Callback into the provider to be called to        initialize a resource accumulator buffer. If NULL, the resource        manager will 0-init the buffer. This callback gives resource        providers the opportunity to do any special initialization        processing on a resource accumulator buffer before it is used.    -   The prototype for the AccumulatorInIt function is as follows:

NTSTATUS AccumulatorInit ( IN PVOID ProviderContext, IN OUT PVOIDAccumulator );

-   -   AccumulatorFree: Callback into the provider to be called before        the resource manager frees an accumulator buffer. If NULL, the        resource manager will not take any special actions when freeing        an accumulator buffer. This callback gives the resource provider        the opportunity to free or otherwise deallocate any memory        pointed to by fields within the accumulator buffer. The resource        provider should not attempt to free the resource accumulator        buffer.    -   The prototype for the AccumulatorFree function is as follows:

NTSTATUS AccumulatorFree ( IN PVOID ProviderContext, IN OUT PVOIDAccumulator );

-   -   AccumulatorCopy: Callback into the provider to be called to copy        from one resource accumulator buffer to another. If NULL, the        resource manager will just copy the buffer directly (e.g. using        memcpy). This callback gives the resource provider the        opportunity to copy any memory pointed to by fields within the        accumulator buffer.    -   The prototype for the AccumulatorCopy function is as follows:

NTSTATUS AccumulatorCopy ( IN PVOID ProviderContext, IN PVOIDSrcAccumulator, IN OUT PVOID DestAccumulator );

-   -   The provider should assume that DestAccumulator is uninitialized        memory. Specifically, the DestAccumulator buffer is not passed        to any AccumulatorInIt function before it is passed to the        AccumulatorCopy function.    -   NotifyOnReserve: Callback into the provider to inform it that a        resource has been reserved.    -   The prototype for the NotifyOnReserve function is as follows:

NTSTATUS NotifyOnReserve ( IN PVOID ProviderContext, IN PVOIDAttributeBuffer, );

-   -   The provider may fail this call by returning        STATUS_RESOURCE_UNAVAILABLE. For example, maybe the device went        bad and provider got this notification before it could        unregister the resource. In this case, RM will rollback the        reservation. The provider at the earliest opportunity will        update the resource count.    -   NotifyOnUnReserve: Callback into the provider to inform it that        a previously reserved resource amount has been unreserved.    -   The prototype for the NotifyOnReserve function is as follows:

NTSTATUS NotifyOnReserve ( IN PVOID ProviderContext, IN PVOIDAttributeBuffer, );

-   -   NotifyOnRemove: Callback into the provider to inform it that a        previously added resource is being removed, either due to an        error in the activity, or because a higher-level resource in the        tree was removed, or because the provider called        RmRemoveResourceFromConfiguration.    -   The prototype for the NotifyOnRemove function is as follows:

NTSTATUS NotifyOnRemove ( IN PVOID ProviderContext, IN PVOIDAttributeBuffer, );

-   -   The provider should use this callback to free up any data        structures associated with the resource.    -   Note 1: The resource manager will call the NotifyOnRemove        function from within RmRemoveResourceFromConfiguration.        Therefore, the provider should not attempt to free any data        structures associated with the reservation after returning from        RmRemoveResourceFromConfiguration.    -   Note 2: The resource manager will not call the NotifyOnRemove        function as a side effect of a failure within        RmAddResourceToConfiguration. Therefore, if        RmAddResourceToConfiguration fails for some reason, the provider        should handle the cleanup of any data structures as part of        handling that error.    -   ResourceHandle: Handle returned from RmRegisterResource to be        used in other calls into the resource manager.

d) Return Values

STATUS_SUCCESS: The resource has been registered successfully. Any otherreturn value signifies an error.

2. RmUnregisterResource

a) Prototype

NTSTATUS RmUnregisterResource ( IN RM_HANDLE ResourceHandle );

b) Description

The resource provider should call this function when it needs tounregister its resource from the resource manager. The provider shoulduse RmRemoveResourceFromConfiguration to remove any outstandingresources from all configurations before making this call. If theprovider does not do this, RM will automatically purge all resourcesfrom the provider as if the provider had calledRmRemoveResourceFromConfiguration.

c) Parameters

ResourceHandle: Handle originally returned from RmRegisterResource.

d) Return Values

STATUS_SUCCESS: The resource was successfully unregistered

3. RmLockResource

NTSTATUS RmLockResource ( IN RM_HANDLE ResourceHandle, );

a) Description

The resource provider should call this function before it modifies anyinternal state, such as when the amount of resources that the providerrepresents has changed. This will allow the resource manager tosynchronize with any changes to the provider's internal state.

b) Parameters

ResourceHandle: Handle originally returned from RmRegisterResource

c) Return Values

STATUS_SUCCESS: The resource was successfully locked.

4. RmUnlockResource

NTSTATUS RmUnlockResource ( IN RM_HANDLE ResourceHandle, IN BOOL Update);

a) Description

The resource provider should call this function after it has completedmodifying any internal state, such as when the amount of resources thatthe provider represents has changed. This will allow the resourcemanager to recalculate the resource usage of all activities in thesystem in response to changes in resource availability.

b) Parameters

ResourceHandle: Handle originally returned from RmRcgisterResource

Update: This parameter should be set to TRUE if the amount of resourceshas changed. This will tell the resource manager to recalculate theresource usage of the system.

c) Return Values

STATUS_SUCCESS: The resource was successfully unlocked.

5. RmAddResourceToConfiguration

a) Prototype

NTSTATUS RmAddResourceToConfiguration ( IN PRM_ACTIVITY Activity, INPVOID Tag OPTIONAL, IN RM_HANDLE ParentId, IN RM_RESOURCEResourceHandle, IN PVOID AttributeBuffer OPTIONAL, IN ULONGAttributeBufferSize, OUT PRM_HANDLE ResourceId );

b) Description

Adds resource to a configuration.

c) Parameters

Activity: Previously created activity object.

Tag: A pointer supplied by the parent to uniquely identify/tag the childthat is getting added.

ParentId: Resource handle of the parent of the resource that is gettingadded.

ResourceHandle: Handle returned from RmRegisterResource.

AttributeBuffer: Pointer to a buffer that contains data that isunderstood only by the provider (e.g., resource amount). IfAttribributeBufferSize is zero, this must be NULL.

Note that the resource manager will make an internal copy of this bufferfor all future callback functions. Therefore, it is acceptable for theresource provider to create this buffer on its own stack and/or discardit after returning from RmAddResourceToConfiguration. However, theresource manager will not copy data pointed to by any internal fields ofthis structure. Such data must be maintained by the provider and must beaccessible within any process context.

AttributeBufferSize: Size in bytes of AttributeBuffer. Should be zero ifno data in buffer.

ResourceId: Handle returned by this call to represent this resourceallocation.

d) Return Values

STATUS_SUCCESS or appropriate error code.

6. RmRemoveResourceFromConfiguration

a) Prototype

NTSTATUS RmRemoveResourceFromConfiguration ( IN PRM_ACTIVITY Activity,IN RM_HANDLE ResourceId );

b) Description

Removes a resource allocation from a configuration. If the resource isassigned to a provider it is freed automatically.

c) Parameters

Activity: Previously created activity object.

ResourceId: The handle returned from RmAddResourceToConfiguration.

d) Return Values

STATUS_SUCCESS or appropriate error code.

7. RmSetResourceAttributes

a) Prototype

NTSTATUS RmSetResourceAttributes ( IN PRM_ACTIVITY Activity, INRM_HANDLE ResourceID, IN PVOID AttributeBuffer OPTIONAL, IN ULONGAttributeBufferSize );

b) Description

Changes the attributes on the resource.

c) Parameters

Activity: Previously created activity object.

ResourceID: The handle returned from RmAddResourceToConfiguration.

AttributeBuffer: Pointer to a buffer containing the new attributes. IfAttribributeBufferSize is zero, this must be NULL.

AttributeBufferSize: Size of buffer in bytes.

d) Return Values

STATUS_SUCCESS or appropriate error code.

8. RmGetDefaultActivityAndConfiguration

a) Prototype

NTSTATUS RmGetDefaultActivityAndConfiguration( OUT PRM_ACTIVITY*Activity, OUT PRM_HANDLE ConfigId );

b) Description

Returns the default activity and configuration. Providers can use thiscall in cases where the provider does not know the activity andconfiguration to add resources to, such as the case of a legacy client.

c) Parameters

Activity: Returns the default activity.

ConfigId: Returns the default configuration.

d) Return Values

STATUS_SUCCESS or appropriate error code.

9. RmGetAttributeBuffer

a) Prototype

NTSTATUS RmGetAttributeBuffer( IN PRM_ACTIVITY Activity, IN RM_HANDLEResourceId, IN PVOID *Buffer );

b) Description

Gets the attribute buffer associated with a resource descriptor.

c) Parameters

Activity: Pointer to a previously created activity.

ResourceID: Handle to a resource descriptor in the activity by the aboveargument.

Buffer: Variable that receives the pointer to the attribute buffer.

d) Return Values

STATUS_SUCCESS or appropriate error code.

B. Consumer Interface

Consumer API Calls

1. RmCreateActivity

a) Prototype

NTSTATUS RmCreateActivity ( OUT PRM_ACTIVITY ActivityObject, INACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributesOPTIONAL, IN REFGUID TypeGuid );

b) Description

This function creates a new activity object.

c) Parameters

ActivityObject: A pointer to the created activity object is returnedhere.

DesiredAccess: Access rights, e.g. ACTIVITY_QUERY_STATE,ACTIVITY_MODIFY_STATE.

ObjectAttributes: Supplies standard object attributes such as name,security, etc.

TypeGuid: The type of the activity, one of a set of predefined types.The activity type may be used to help determine the relative priority ofthe activity with respect to other activities.

d) Return Values

STATUS_SUCCESS or appropriate error code.

e) Notes

A single resource consumer can create multiple activities.

2. RmReserveResources

a) Prototype

NTSTATUS RmReserveResources ( IN PRM_ACTIVITY Activity, IN OUTPRM_ACTIVITY_STATUS ActivityStatus, IN PKEVENT Event, IN RM_HANDLEDesiredConfigId, );

b) Description

RM reserves resources for a configuration in the activity. Theconfiguration chosen is based on availability of resources and theactivity relative priority. The caller can optionally supply a validConfigId in which case RM will only attempt to reserve thatconfiguration and fail otherwise. If the activity already had asatisfied configuration (i.e., resources are assigned to aconfiguration) on entry then the RM will interpret this as a request tosee if more desirable configuration is available. RM will guarantee thaton return at least the existing configuration is still available(assuming that it has not been evicted for other reasons, such as ahigher priority activity needing resources).

This call is asynchronous. The use of the ActivityStatus and Eventparameters allow this caller to wait until RM has determined whether therequest can be satisfied.

c) Parameters

Activity: Handle of previously created activity.

ActivityStatus: This structure is used by RM to return the status of therequest after it has been completed. This structure is defined as:

typedef struct _RM_ACTIVITY_STATUS { NTSTATUS Status; ULONG Information;} RM_ACTIVITY_STATUS, *PRM_ACTIVITY_STATUS;

When used with RmReserveResources, the Status field is used to hold theresult of the operation, and the Information field receives theconfiguration ID that the RM satisfied. The information field is validonly if the value of Status is STATUS_SUCCESS.

Event: If RM cannot complete the reservation immediately, the callershould wait on this event to determine when the operation is complete,

DesiredConfigId: The caller may choose to reserve a specificconfiguration ID by initializing this parameter with that ID. Otherwise,it should be initialized with 0.

d) Return Values

STATUS_SUCCESS: if the RM can satisfy any configuration in the activity.

STATUS_RESOURCE_UNAVAILABLE: none of the configurations can be currentlysatisfied as resources are assigned to other higher priority activities.

STATUS_PENDING: if RM cannot complete the operation yet. In this case,the caller should wait on the Event handle until the operation iscompleted.

3. RmUnreserveResources

a) Prototype

NTSTATUS RmUnreserveResources ( IN PRM_ACTIVITY Activity );

b) Description

Unreserves resources associated with a configuration in an activity.

c) Parameters

Activity: Handle of previously created activity.

d) Return Values

STATUS_SUCCESS or error code.

4. RmGetActivityStatus

a) Prototype

NTSTATUS RmGetActivityStatus ( IN PRM_ACTIVITY Activity, IN OUTPRM_ACTIVITY_STATUS ActivityStatus, IN PKEVENT Event );

b) Description

Returns information on the changes to the status of an activity. Thiscall is asynchronous. The use of the ActivityStatus and Event parametersallow the caller to wait until RM has determined that the status of theactivity has changed.

c) Parameters

Activity: Handle of previously created activity.

ActivityStatus: This structure is used by RM to return the status of therequest after it has been completed. This structure is defined as:

typedef struct _RM_ACTIVITY_STATUS { NTSTATUS Status; ULONG Information;} RM_ACTIVITY_STATUS, *PRM_ACTIVITY_STATUS;

When used with RmGetActivityStatus, the Status field is used to hold theresult of the operation, and the Information field receives the reason.Examples include RM_RELEASE_CONFIGURATION, RM_BETTER_CONFIGURATION, etc.The information field is valid only if the value of Status isSTATUS_SUCCESS.

Event: If there is currently no status pending, the caller should waiton this event to determine when new status information is available.

d) Return Values

STATUS_SUCCESS or appropriate error code.

5. RmCancelRequest

a) Prototype

NTSTATUS RmCancelRequest( IN PRM_ACTIVITY Activity, );

b) Description

This call may be used to cancel any pending asynchronous calls.Currently, only RmReserveResources and RmGetResourceStatus are definedto be asynchronous.

This call cancels any pending RM requests which were initiated from thesame thread calling RmCancelRequest. When RM cancels a transaction, itsets the Status field of the RM_ACTIVITY_STATUS structure toSTATUS_CANCELLED and signals the corresponding event.

After canceling a transaction, the caller should always check the statusfield of the RM_ACTIVITY_STATUS structure to verify whether thetransaction was actually cancelled, or whether the transactionsuccessfully completed before it was cancelled.

c) Parameters

Activity: Handle of previously created activity.

d) Return Values

STATUS_SUCCESS: RM has canceled all transactions of the specified type.

6. RmCreateConfiguration

a) Prototype

NTSTATUS RmCreateConfiguration ( IN PRM_ACTIVITY Activity, IN ULONGMerit, OUT PRM_HANDLE ConfigId );

b) Description

Create configurations in the specified activity.

c) Parameters

Activity: Handle of previously created activity.

Merit—Importance of this configuration relative to the otherconfigurations in this activity.

ConfigId—Handle to created configuration.

d) Return Values

STATUS_SUCCESS or appropriate error code.

7. RmRemoveConfiguration

a) Prototype

NTSTATUS RmRemoveConfiguration ( IN PRM_ACTIVITY Activity, IN RM_HANDLEConfigId );

b) Description

Removes configurations from the specified activity.

c) Parameters

Activity: Handle of previously created activity.

ConfigId: Handle to the configuration to be removed. RM willautomatically clean up any reserved resources.

d) Return Values

STATUS_SUCCESS or appropriate error code.

8. RmGetResourceParent

a) Prototype

NTSTATUS RmGetResourceParent ( IN PRM_ACTIVITY Activity, IN RM_HANDLEResourceIdIn, OUT PRM_HANDLE ResourceIdReturned );

b) Description

Returns the parent ResourceId of ResourceIdIn.

c) Parameters

Activity: Handle of previously created activity.

ResourceIdIn: Handle to a ResourceId.

ResourceIdReturned: Pointer to a ResourceId. The resulting ResourceId isreturned at this location.

d) Return Values

STATUS_SUCCESS or appropriate error code.

9. RmGetResourceChild

a) Prototype

NTSTATUS RmGetResourceChild ( IN PRM_ACTIVITY Activity, IN RM_HANDLEResourceIdParent, IN RM_HANDLE ResourceIdIn, OUT PRM_HANDLEResourceIdReturned );

b) Description

Returns the first child ResourceId of ResourceIdIn.

c) Parameters

Activity: Handle of previously created activity.

ResourceIdParent: Handle to a ResourceId or ConfigurationId.

ResourceIdIn: Handle to a ResourceId. If set to −1, the function returnsthe first child resource.

ResourceIdReturned: Pointer to a ResourceId. The resulting ResourceId isreturned at this location.

d) Return Values

STATUS_SUCCESS or appropriate error code.

10 RmGetResourceInformation

a) Prototype

NTSTATUS RmGetResourceInformation ( IN PRM_ACTIVITY Activity, INRM_HANDLE ResourceId, IN RM_RESOURCE_INFO_TYPE ResourceInfoType, INULONG AvailableBufferSize, OUT ULONG *RequiredBufferSize, OUT PVOID*ResourceInfo );

b) Description

Returns information about the specified ResourceId.

c) Parameters

Activity: Handle of previously created activity.

ResourceId: Handle to a ResourceId or ConfigurationId.

ResourceInfoType: An enum value specifying what type of information toreturn. Currently defined values, and the corresponding buffers theyreturn, are:

-   -   ResourceInfo_Default    -   Returns the following structure in the buffer:

typedef struct _RM_RESOURCE_INFO_DEFAULT { BOOL FailedReservation; //This resource failed its last reservation BOOLDescendantFailedReservation; // A descendant failed its last reservationBOOL PeerFailedReservation; // Peer of same provider failed lastreservation GUID ResourcePoolGUID; // Resource GUID RM_HANDLEResourcePoolHandle; // Handle of provider ULONG TagLength; // Size oftag buffer } RM_RESOURCE_INFO_DEFAULT;

-   -   ResourceInfo_Tag    -   Returns the tag originally specified when the resource was        added.    -   ResourceInfo_Amount    -   Returns the following structure in the buffer:

typedef struct _RM_RESOURCE_INFO_AMOUNT { ULONG AmountReserved; ULONGAmountInSystem; ULONG AmountAvailable; ULONG AmountUsed; ULONGAmountUsedPeak; WCHAR AmountLabel[32]; WCHAR ProviderDescription[128]; }RM_RESOURCE_INFO_AMOUNT;

AvailableBufferSize: Size of buffer in bytes.

RequiredBufferSize: Size of data returned in buffer in bytes.

ResourceInfo: Pointer to a buffer into which RM will store the requesteddata.

d) Return Values

STATUS_SUCCESS or appropriate error code.

11. RmGetLastAccumulator

a) Prototype

NTSTATUS RmGetLastAccumulator( IN PRM_ACTIVITY Activity, IN RM_HANDLEProviderHandle, OUT PVOID *AccumulatorBuffer );

b) Description:

Returns the last accumulator buffer before adding any of the specifiedactivities' resources into it.

c) Parameters:

Activity: Previously created activity object.

ProviderHandle: Handle returned from RmRegisterResource.

AccumulatorBuffer: A pointer to the accumulator buffer is stored here onsuccessful return.

d) Return Values

STATUS_SUCCESS or appropriate error code.

e) Comments

This call could be used in conjunction with RmGetResourcePeer to allow aresource provider to rebalance the resources within an activity if itwould otherwise be evicted due to lack of resources.

12. RmGetResourcePeer

a) Prototype

NTSTATUS RmGetResourcePeer ( IN PRM_ACTIVITY Activity, IN RM_HANDLEResourceProvider, IN RM_HANDLE ResourceIdIn, OUT PRM_HANDLEResourceIdReturned );

b) Description

Returns the ResourceId of the next resource in the specified activitywhich has the specified resource provider.

c) Parameters

Activity: Handle of previously created activity.

ResourceProvider: Handle to a resource provider.

ResourceIdIn: Handle to a ResourceId. If this parameter is set to −1,the function returns the first resource associated with the specifiedprovider.

ResourceIdReturned: Pointer to a ResourceId. The resulting ResourceId isreturned at this location.

d) Return Values

STATUS_SUCCESS or appropriate error code.

e) Comments

Implementation of this call might invoke the following changes to theRmGetResourceInformation call:

1. Add a ResourceInfoType of ResourceInfo_Attributes to returns theattribute buffer associated with the resource.

2. Add a ULONG AttributeBufferLength field to theRM_RESOURCE_INFO_DEFAULT structure.

CONCLUSION

Although the description above uses language that is specific tostructural features and/or methodological acts, it is to be understoodthat the invention defined in the appended claims is not limited to thespecific features or acts described. Rather, the specific features andacts are disclosed as exemplary forms of implementing the invention.

1. A resource management method comprising: representing, as ahierarchical tree structure, a plurality of resources that are targetedby a first resource consumer to perform a task in a targetedconfiguration, each resource being associated with a resource providerthat manages its corresponding resource, at least one of the pluralityof resources being represented as a parent node, at least one otherresource being represented as a child node of the parent node;monitoring, by a processor configured with executable instructions,whether the other resource is capable of performing functionalitytargeted by the first resource consumer to perform its part of the task;determining that the other resource that is represented as the childnode is unable to perform the functionality targeted by the firstresource consumer to perform its part of the task as a result of theother resource being reserved or used by a second resource consumer thathas priority over the first resource consumer; performing the task forthe first resource consumer in a fallback configuration until the otherresource that is represented as the child node is able to perform thefunctionality targeted; and switching from the fallback configuration tothe targeted configuration to continue performing the task.
 2. Theresource management method of claim 1, further comprising notifying thefirst resource consumer in the event that the other resource is unableto perform the functionality targeted by the first resource consumer toperform its part of the task.
 3. The resource management method of claim2, further comprising notifying the first resource consumer when theother resource is able to perform the functionality targeted by thefirst resource consumer to perform its part of the task when the otherresource becomes available.
 4. The resource management method of claim1, wherein the plurality of resources are capable of being requested forreservation by the first resource consumer.
 5. The resource managementmethod of claim 3, wherein the other resource becomes available whenanother task frees at least a portion of the other resource.
 6. Theresource management method of claim 1, further comprising reserving theplurality of resources for the task in the targeted configuration at afirst time, and wherein the other resource is unable to perform thefunctionality targeted by the first resource consumer to perform itspart of the task when the second resource consumer performs another taskthat reserves the other resource at a second time after the first time.7. The resource management method of claim 1, further comprisingnotifying the resource provider that is associated with the parent node.8. The resource management method of claim 7, wherein the notifying ofthe resource provider that is associated with the parent node comprises:notifying the resource provider that is associated with the parent nodewith a notification that is specific to the resource provider from whichthe notification originated; translating the specific notification intoa different form of notification; and using the different form ofnotification to notify the first resource consumer that the resourcewith which the child node is associated is not available.
 9. Theresource management method of claim 8, wherein using the different formof notification comprises presenting one or more options to the firstresource consumer that can be selected by the first resource consumer tostill perform the task, the one or more options including the fallbackconfiguration.
 10. The resource management method of claim 1, furthercomprising using the notified resource provider so that the task canstill be performed.
 11. A resource management method comprising:defining a chain of a plurality of resource providers each of whichbeing associated with a different resource consumed by a first resourceconsumer to perform a task in a first configuration; determining, by aprocessor configured with executable instructions, that a correspondingresource with which a first resource provider is associated isunavailable due to being reserved or used by a second resource consumerthat has priority over the first resource consumer; performing the taskfor the first resource consumer in a second configuration until thecorresponding resource is available; and switching from the secondconfiguration to the first configuration to continue performing thetask.
 12. A resource management method comprising: defining a firstconfiguration including a chain of resource providers each of whichbeing associated with a different resource that a resource managerattempts to reserve on behalf of a first resource consumer to perform atask, the chain of resource providers including at least oneparent-child relationship; reporting, by a processor configured withexecutable instructions, an error to a child resource provider when theresource manager fails to reserve a first resource with which the childresource provider is associated, the error resulting from the firstresource being unavailable due to a priority of a second resourceconsumer; reporting the error up the chain of resource providers in thefirst configuration; reporting the error from a parent resource providerat the top of the chain to the first resource consumer; and presentingthe first resource consumer with at least one option that will enablethe task to be performed with a different configuration of resources,the different configuration of resources including a second resource notdefined in the first configuration, and not including the first resourcethat the resource manager fails to reserve.
 13. A system comprising: aprocessor; a first resource consumer that is aware of a first set of oneor more resources required to perform a task, wherein the first set ofone or more resources are associated with one or more resourceproviders, each of the one or more resource providers being configuredto call on a second set of one or more resources from which resources inthe first set depend upon to perform respective portions of the task;and a resource manager that maintains a hierarchical tree structure thatdescribes a configuration of resources from the first and second setsrequired to perform the task, wherein the hierarchical tree describes atleast one parent-child relationship between a parent resource from thefirst set and a child resource from the second set, wherein the resourcemanager is configured to: reserve the first set of one or more resourcesand the second set of one or more resources; receive an errornotification from a child resource provider associated with the childresource when reservation of the child resource by the resource managerfails due to a second resource consumer having priority over the firstresource consumer; report the error notification to a parent resourceprovider associated with the parent resource that depends upon the childresource, so that the parent resource can translate the errornotification into terms the first resource consumer understands; andpresent the first resource consumer with the translated errornotification and present one or more alternative configurations ofresources which the first resource consumer can select from to stillperform the task.
 14. The system as recited in claim 13, wherein thefirst resource consumer is unaware of the second set of one or moreresources and their corresponding resource providers.